use of com.axelor.apps.hr.db.LeaveRequest in project axelor-open-suite by axelor.
the class LeaveController method editLeave.
public void editLeave(ActionRequest request, ActionResponse response) {
try {
User user = AuthUtils.getUser();
List<LeaveRequest> leaveList = Beans.get(LeaveRequestRepository.class).all().filter("self.user = ?1 AND self.company = ?2 AND self.statusSelect = 1", user, user.getActiveCompany()).fetch();
if (leaveList.isEmpty()) {
response.setView(ActionView.define(I18n.get("LeaveRequest")).model(LeaveRequest.class.getName()).add("form", "leave-request-form").map());
} else if (leaveList.size() == 1) {
response.setView(ActionView.define(I18n.get("LeaveRequest")).model(LeaveRequest.class.getName()).add("form", "leave-request-form").param("forceEdit", "true").context("_showRecord", String.valueOf(leaveList.get(0).getId())).map());
} else {
response.setView(ActionView.define(I18n.get("LeaveRequest")).model(Wizard.class.getName()).add("form", "popup-leave-request-form").param("forceEdit", "true").param("popup", "true").param("show-toolbar", "false").param("show-confirm", "false").param("forceEdit", "true").param("popup-save", "false").map());
}
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.apps.hr.db.LeaveRequest 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.LeaveRequest in project axelor-open-suite by axelor.
the class LeaveController method validate.
/**
* Validates leave request and sends an email to the applicant.
*
* @param request
* @param response
* @throws AxelorException
*/
public void validate(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());
leaveService.validate(leaveRequest);
Message message = leaveService.sendValidationEmail(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)));
}
Beans.get(PeriodService.class).checkPeriod(leaveRequest.getCompany(), leaveRequest.getToDateT().toLocalDate(), leaveRequest.getFromDateT().toLocalDate());
} catch (Exception e) {
TraceBackService.trace(response, e);
} finally {
response.setReload(true);
}
}
use of com.axelor.apps.hr.db.LeaveRequest in project axelor-open-suite by axelor.
the class EmployeeServiceImpl method getDaysWorkedInPeriod.
@Override
public BigDecimal getDaysWorkedInPeriod(Employee employee, LocalDate fromDate, LocalDate toDate) throws AxelorException {
BigDecimal daysWorks = getDaysWorksInPeriod(employee, fromDate, toDate);
BigDecimal daysLeave = BigDecimal.ZERO;
List<LeaveRequest> leaveRequestList = Beans.get(LeaveRequestRepository.class).all().filter("self.user = ?1 AND self.duration >= 1 AND self.statusSelect = ?2 AND (self.fromDateT BETWEEN ?3 AND ?4 OR self.toDateT BETWEEN ?3 AND ?4 OR ?3 BETWEEN self.fromDateT AND self.toDateT OR ?4 BETWEEN self.fromDateT AND self.toDateT)", employee.getUser(), LeaveRequestRepository.STATUS_VALIDATED, fromDate, toDate).fetch();
for (LeaveRequest leaveRequest : leaveRequestList) {
daysLeave = daysLeave.add(Beans.get(LeaveService.class).computeDuration(leaveRequest, fromDate, toDate));
}
return daysWorks.subtract(daysLeave);
}
Aggregations