use of com.axelor.auth.db.User 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.auth.db.User in project axelor-open-suite by axelor.
the class HumanResourceMobileController method getKilometricAllowParam.
/*
* This method is used in mobile application.
* @param request
* @param response
*
* POST /open-suite-webapp/ws/action/com.axelor.apps.hr.mobile.HumanResourceMobileController:getKilometricAllowParam
* Content-Type: application/json
*
* URL: com.axelor.apps.hr.mobile.HumanResourceMobileController:getKilometricAllowParam
* fields: no field
*
* payload:
* { "data": {
* "action": "com.axelor.apps.hr.mobile.HumanResourceMobileController:getKilometricAllowParam"
* } }
*/
@Transactional
public void getKilometricAllowParam(ActionRequest request, ActionResponse response) {
List<Map<String, String>> dataList = new ArrayList<>();
try {
User user = AuthUtils.getUser();
List<EmployeeVehicle> employeeVehicleList = Beans.get(EmployeeVehicleRepository.class).all().filter("self.employee = ?1", user.getEmployee()).fetch();
// Not sorted by default ?
employeeVehicleList.sort((employeeVehicle1, employeeVehicle2) -> employeeVehicle1.getKilometricAllowParam().getCode().compareTo(employeeVehicle2.getKilometricAllowParam().getCode()));
for (EmployeeVehicle employeeVehicle : employeeVehicleList) {
Map<String, String> map = new HashMap<>();
map.put("name", employeeVehicle.getKilometricAllowParam().getName());
map.put("id", employeeVehicle.getKilometricAllowParam().getId().toString());
dataList.add(map);
}
response.setData(dataList);
} catch (Exception e) {
response.setStatus(-1);
response.setError(e.getMessage());
}
}
use of com.axelor.auth.db.User in project axelor-open-suite by axelor.
the class HumanResourceMobileController method insertOrUpdateTSLine.
/*
* This method is used in mobile application.
* It was in TimesheetServiceImpl
* @param request
* @param response
*
* POST /open-suite-webapp/ws/action/com.axelor.apps.hr.mobile.HumanResourceMobileController:insertOrUpdateTSLine
* Content-Type: application/json
*
* URL: com.axelor.apps.hr.mobile.HumanResourceMobileController:insertOrUpdateTSLine
* fields: (id,) project, activity, date, duration, comments
*
* payload:
* { "data": {
* "action": "com.axelor.apps.hr.mobile.HumanResourceMobileController:insertOrUpdateTSLine",
* "id": 1,
* "project": 1,
* "activity": 2,
* "date": "2018-02-22",
* "duration": 10,
* "comments": "no"
* } }
*/
@Transactional
public void insertOrUpdateTSLine(ActionRequest request, ActionResponse response) {
// insert TimesheetLine
try {
Map<String, Object> requestData = request.getData();
User user = AuthUtils.getUser();
Project project = Beans.get(ProjectRepository.class).find(new Long(request.getData().get("project").toString()));
Product product = Beans.get(ProductRepository.class).find(new Long(request.getData().get("activity").toString()));
LocalDate date = LocalDate.parse(request.getData().get("date").toString(), DateTimeFormatter.ISO_DATE);
TimesheetRepository timesheetRepository = Beans.get(TimesheetRepository.class);
TimesheetService timesheetService = Beans.get(TimesheetService.class);
TimesheetLineService timesheetLineService = Beans.get(TimesheetLineService.class);
if (user != null) {
Timesheet timesheet = timesheetRepository.all().filter("self.statusSelect = 1 AND self.user.id = ?1", user.getId()).order("-id").fetchOne();
if (timesheet == null) {
timesheet = timesheetService.createTimesheet(user, date, date);
}
BigDecimal hours = new BigDecimal(request.getData().get("duration").toString());
TimesheetLine line;
Object idO = requestData.get("id");
if (idO != null) {
line = timesheetLineService.updateTimesheetLine(Beans.get(TimesheetLineRepository.class).find(Long.valueOf(idO.toString())), project, product, user, date, timesheet, hours, request.getData().get("comments").toString());
} else {
line = timesheetLineService.createTimesheetLine(project, product, user, date, timesheet, hours, request.getData().get("comments").toString());
}
// convert hours to what is defined in timeLoggingPreferenceSelect
BigDecimal duration = timesheetLineService.computeHoursDuration(timesheet, hours, false);
line.setDuration(duration);
timesheet.addTimesheetLineListItem(line);
timesheetRepository.save(timesheet);
response.setTotal(1);
HashMap<String, Object> data = new HashMap<>();
data.put("id", line.getId());
response.setData(data);
}
} catch (Exception e) {
TraceBackService.trace(e);
}
}
use of com.axelor.auth.db.User in project axelor-open-suite by axelor.
the class ICalendarController method showMyEvents.
public void showMyEvents(ActionRequest request, ActionResponse response) {
User user = AuthUtils.getUser();
response.setView(ActionView.define(I18n.get("My events")).model(ICalendarEvent.class.getName()).add("calendar", "calendar-event-all").add("grid", "calendar-event-grid").add("form", "calendar-event-form").domain("self.user.id = :_userId" + " OR self.calendar.user.id = :_userId" + " OR :_userId IN (SELECT attendee.user FROM self.attendees attendee)" + " OR self.organizer.user.id = :_userId" + " OR :_userId IN (SELECT setting.sharedWith FROM self.calendar.sharingSettingList setting WHERE setting.visible = TRUE)").context("_userId", user.getId()).map());
}
use of com.axelor.auth.db.User in project axelor-open-suite by axelor.
the class PartnerController method printClientSituation.
/* Fonction appeler par le bouton imprimer
*
* @param request
* @param response
* @return
*/
public void printClientSituation(ActionRequest request, ActionResponse response) throws AxelorException {
Partner partner = request.getContext().asType(Partner.class);
User user = AuthUtils.getUser();
String name = I18n.get("Customer Situation");
String fileLink = ReportFactory.createReport(IReport.CLIENT_SITUATION, name + "-${date}").addParam("Locale", ReportSettings.getPrintingLocale(partner)).addParam("Timezone", getTimezone(user)).addParam("UserId", user.getId()).addParam("PartnerId", partner.getId()).addParam("PartnerPic", partner.getPicture() != null ? MetaFiles.getPath(partner.getPicture()).toString() : "").generate().getFileLink();
LOG.debug("Printing " + name);
response.setView(ActionView.define(name).add("html", fileLink).map());
}
Aggregations