use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.
the class ExpenseController method computeDistanceAndKilometricExpense.
public void computeDistanceAndKilometricExpense(ActionRequest request, ActionResponse response) throws AxelorException {
// Compute distance.
try {
if (!Beans.get(AppHumanResourceService.class).getAppExpense().getComputeDistanceWithWebService()) {
return;
}
Context context = request.getContext();
ExpenseLine expenseLine = context.asType(ExpenseLine.class);
if (Strings.isNullOrEmpty(expenseLine.getFromCity()) || Strings.isNullOrEmpty(expenseLine.getToCity())) {
return;
}
KilometricService kilometricService = Beans.get(KilometricService.class);
BigDecimal distance = kilometricService.computeDistance(expenseLine);
expenseLine.setDistance(distance);
response.setValue("distance", distance);
if (expenseLine.getKilometricAllowParam() == null || expenseLine.getExpenseDate() == null || expenseLine.getKilometricTypeSelect() == 0) {
return;
}
Expense expense = expenseLine.getExpense();
if (expense == null) {
expense = context.getParent().asType(Expense.class);
}
Employee employee = expense.getUser().getEmployee();
if (employee == null) {
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.LEAVE_USER_EMPLOYEE), expense.getUser().getName());
}
BigDecimal amount = kilometricService.computeKilometricExpense(expenseLine, employee);
response.setValue("totalAmount", amount);
response.setValue("untaxedAmount", amount);
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.
the class TimesheetReportServiceImpl method getTotalWorksHours.
private BigDecimal getTotalWorksHours(User user, LocalDate date, boolean isPublicHoliday, BigDecimal dailyWorkingHours) throws AxelorException {
Employee employee = user.getEmployee();
BigDecimal worksHour = employeeService.getDaysWorksInPeriod(employee, date, date).multiply(employee.getDailyWorkHours()).setScale(2, RoundingMode.HALF_UP);
if (isPublicHoliday) {
worksHour = worksHour.add(dailyWorkingHours);
}
double extraHours = extraHoursLineRepository.all().filter("self.user = ? AND self.date = ? AND (self.extraHours.statusSelect = ? OR self.extraHours.statusSelect = ?)", user, date, ExtraHoursRepository.STATUS_VALIDATED, ExtraHoursRepository.STATUS_CONFIRMED).fetchStream().mapToDouble(ehl -> Double.parseDouble(ehl.getQty().toString())).sum();
worksHour = worksHour.add(new BigDecimal(extraHours));
return worksHour.setScale(2, RoundingMode.HALF_UP);
}
use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.
the class TimesheetReportServiceImpl method getTotalWeekWorksHours.
private BigDecimal getTotalWeekWorksHours(User user, LocalDate fromDate, LocalDate toDate, BigDecimal publicHolidays) throws AxelorException {
Employee employee = user.getEmployee();
BigDecimal worksHour = employeeService.getDaysWorksInPeriod(employee, fromDate, toDate).multiply(employee.getDailyWorkHours()).setScale(2, RoundingMode.HALF_UP);
worksHour = worksHour.add(publicHolidays.multiply(employee.getDailyWorkHours()));
double extraHours = extraHoursLineRepository.all().filter("self.user = ? AND (self.date BETWEEN ? AND ?) AND (self.extraHours.statusSelect = ? OR self.extraHours.statusSelect = ?)", user, fromDate, toDate, ExtraHoursRepository.STATUS_VALIDATED, ExtraHoursRepository.STATUS_CONFIRMED).fetchStream().mapToDouble(ehl -> Double.parseDouble(ehl.getQty().toString())).sum();
worksHour = worksHour.add(new BigDecimal(extraHours));
return worksHour.setScale(2, RoundingMode.HALF_UP);
}
use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.
the class ProjectPlanningTimeController method updateIsIncludeInTuronverForecast.
/**
* Invert value of 'isIncludeInTuronverForecast' field and save the record.
*
* @param request
* @param response
* @throws AxelorException
*/
@Transactional
public void updateIsIncludeInTuronverForecast(ActionRequest request, ActionResponse response) {
try {
ProjectPlanningTime projectPlanningTime = request.getContext().asType(ProjectPlanningTime.class);
projectPlanningTime = Beans.get(ProjectPlanningTimeRepository.class).find(projectPlanningTime.getId());
projectPlanningTime.setIsIncludeInTurnoverForecast(!projectPlanningTime.getIsIncludeInTurnoverForecast());
Beans.get(ProjectPlanningTimeRepository.class).save(projectPlanningTime);
response.setValue("isIncludeInTurnoverForecast", projectPlanningTime.getIsIncludeInTurnoverForecast());
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.
the class TimesheetController method refuse.
// action called when refusing a timesheet. Changing status + Sending mail to Applicant
public void refuse(ActionRequest request, ActionResponse response) throws AxelorException {
try {
Timesheet timesheet = request.getContext().asType(Timesheet.class);
timesheet = Beans.get(TimesheetRepository.class).find(timesheet.getId());
Message message = Beans.get(TimesheetService.class).refuseAndSendRefusalEmail(timesheet);
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);
}
}
Aggregations