use of com.axelor.apps.hr.db.LeaveLine in project axelor-open-suite by axelor.
the class LeaveManagementController method computeQuantityAvailable.
public void computeQuantityAvailable(ActionRequest request, ActionResponse response) {
LeaveLine leaveLine = request.getContext().asType(LeaveLine.class);
leaveLine = Beans.get(LeaveManagementService.class).computeQuantityAvailable(leaveLine);
response.setValue("quantity", leaveLine.getQuantity());
response.setValue("totalQuantity", leaveLine.getTotalQuantity());
response.setValue("leaveManagementList", leaveLine.getLeaveManagementList());
}
use of com.axelor.apps.hr.db.LeaveLine in project axelor-open-suite by axelor.
the class LeaveController method send.
// sending leave request and an email to the manager
public void send(ActionRequest request, ActionResponse response) {
try {
LeaveService leaveService = Beans.get(LeaveService.class);
LeaveRequest leaveRequest = request.getContext().asType(LeaveRequest.class);
leaveRequest = Beans.get(LeaveRequestRepository.class).find(leaveRequest.getId());
if (leaveRequest.getUser().getEmployee().getWeeklyPlanning() == null) {
response.setAlert(String.format(I18n.get(IExceptionMessage.EMPLOYEE_PLANNING), leaveRequest.getUser().getEmployee().getName()));
return;
}
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 && leaveLine.getQuantity().subtract(leaveRequest.getDuration()).signum() < 0) {
if (!leaveRequest.getLeaveReason().getAllowNegativeValue() && !leaveService.willHaveEnoughDays(leaveRequest)) {
String instruction = leaveRequest.getLeaveReason().getInstruction();
if (instruction == null) {
instruction = "";
}
response.setAlert(String.format(I18n.get(IExceptionMessage.LEAVE_ALLOW_NEGATIVE_VALUE_REASON), leaveRequest.getLeaveReason().getName()) + " " + instruction);
return;
} else {
response.setNotify(String.format(I18n.get(IExceptionMessage.LEAVE_ALLOW_NEGATIVE_ALERT), leaveRequest.getLeaveReason().getName()));
}
}
leaveService.confirm(leaveRequest);
Message message = leaveService.sendConfirmationEmail(leaveRequest);
if (message != null && message.getStatusSelect() == MessageRepository.STATUS_SENT) {
response.setFlash(String.format(I18n.get("Email sent to %s"), Beans.get(MessageServiceBaseImpl.class).getToRecipients(message)));
}
} catch (Exception e) {
TraceBackService.trace(response, e);
} finally {
response.setReload(true);
}
}
use of com.axelor.apps.hr.db.LeaveLine in project axelor-open-suite by axelor.
the class LeaveServiceImpl method manageCancelLeaves.
@Override
@Transactional(rollbackOn = { Exception.class })
public void manageCancelLeaves(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.getStatusSelect() == LeaveRequestRepository.STATUS_VALIDATED) {
if (leave.getInjectConsumeSelect() == LeaveRequestRepository.SELECT_CONSUME) {
leaveLine.setQuantity(leaveLine.getQuantity().add(leave.getDuration()));
} else {
leaveLine.setQuantity(leaveLine.getQuantity().subtract(leave.getDuration()));
}
leaveLine.setDaysValidated(leaveLine.getDaysValidated().subtract(leave.getDuration()));
} else if (leave.getStatusSelect() == LeaveRequestRepository.STATUS_AWAITING_VALIDATION) {
if (leave.getInjectConsumeSelect() == LeaveRequestRepository.SELECT_CONSUME) {
leaveLine.setDaysToValidate(leaveLine.getDaysToValidate().subtract(leave.getDuration()));
} else {
leaveLine.setDaysToValidate(leaveLine.getDaysToValidate().add(leave.getDuration()));
}
}
}
use of com.axelor.apps.hr.db.LeaveLine 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.LeaveLine 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());
}
}
Aggregations