Search in sources :

Example 61 with AxelorException

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);
    }
}
Also used : Context(com.axelor.rpc.Context) AxelorException(com.axelor.exception.AxelorException) Employee(com.axelor.apps.hr.db.Employee) AppHumanResourceService(com.axelor.apps.hr.service.app.AppHumanResourceService) Expense(com.axelor.apps.hr.db.Expense) ExpenseLine(com.axelor.apps.hr.db.ExpenseLine) KilometricService(com.axelor.apps.hr.service.KilometricService) BigDecimal(java.math.BigDecimal) AxelorException(com.axelor.exception.AxelorException)

Example 62 with AxelorException

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);
}
Also used : IExceptionMessage(com.axelor.apps.hr.exception.IExceptionMessage) WeeklyPlanning(com.axelor.apps.base.db.WeeklyPlanning) LeaveRequestRepository(com.axelor.apps.hr.db.repo.LeaveRequestRepository) Employee(com.axelor.apps.hr.db.Employee) Inject(com.google.inject.Inject) TimesheetReportRepository(com.axelor.apps.hr.db.repo.TimesheetReportRepository) Transactional(com.google.inject.persist.Transactional) BigDecimal(java.math.BigDecimal) LeaveReasonRepository(com.axelor.apps.hr.db.repo.LeaveReasonRepository) TimesheetReminder(com.axelor.apps.hr.db.TimesheetReminder) Duration(java.time.Duration) Map(java.util.Map) EmployeeService(com.axelor.apps.hr.service.employee.EmployeeService) RoundingMode(java.math.RoundingMode) PublicHolidayService(com.axelor.apps.base.service.publicHoliday.PublicHolidayService) Set(java.util.Set) Message(com.axelor.apps.message.db.Message) TimesheetLine(com.axelor.apps.hr.db.TimesheetLine) Collectors(java.util.stream.Collectors) MessageService(com.axelor.apps.message.service.MessageService) List(java.util.List) Stream(java.util.stream.Stream) TimesheetRepository(com.axelor.apps.hr.db.repo.TimesheetRepository) LocalDate(java.time.LocalDate) TemporalAdjusters(java.time.temporal.TemporalAdjusters) Optional(java.util.Optional) LeaveService(com.axelor.apps.hr.service.leave.LeaveService) ExtraHoursRepository(com.axelor.apps.hr.db.repo.ExtraHoursRepository) LocalDateTime(java.time.LocalDateTime) HashMap(java.util.HashMap) TimesheetReminderLine(com.axelor.apps.hr.db.TimesheetReminderLine) ExtraHoursLineRepository(com.axelor.apps.hr.db.repo.ExtraHoursLineRepository) AppHumanResourceService(com.axelor.apps.hr.service.app.AppHumanResourceService) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) TimesheetLineRepository(com.axelor.apps.hr.db.repo.TimesheetLineRepository) TimesheetReport(com.axelor.apps.hr.db.TimesheetReport) AxelorException(com.axelor.exception.AxelorException) I18n(com.axelor.i18n.I18n) DateTool(com.axelor.apps.tool.date.DateTool) WeekFields(java.time.temporal.WeekFields) TraceBackRepository(com.axelor.exception.db.repo.TraceBackRepository) LeaveRequest(com.axelor.apps.hr.db.LeaveRequest) QueryBuilder(com.axelor.apps.tool.QueryBuilder) TraceBackService(com.axelor.exception.service.TraceBackService) TimesheetReminderRepository(com.axelor.apps.hr.db.repo.TimesheetReminderRepository) Template(com.axelor.apps.message.db.Template) DayPlanning(com.axelor.apps.base.db.DayPlanning) Beans(com.axelor.inject.Beans) WeeklyPlanningService(com.axelor.apps.base.service.weeklyplanning.WeeklyPlanningService) DayOfWeek(java.time.DayOfWeek) TemplateMessageService(com.axelor.apps.message.service.TemplateMessageService) User(com.axelor.auth.db.User) Employee(com.axelor.apps.hr.db.Employee) BigDecimal(java.math.BigDecimal)

Example 63 with AxelorException

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);
}
Also used : IExceptionMessage(com.axelor.apps.hr.exception.IExceptionMessage) WeeklyPlanning(com.axelor.apps.base.db.WeeklyPlanning) LeaveRequestRepository(com.axelor.apps.hr.db.repo.LeaveRequestRepository) Employee(com.axelor.apps.hr.db.Employee) Inject(com.google.inject.Inject) TimesheetReportRepository(com.axelor.apps.hr.db.repo.TimesheetReportRepository) Transactional(com.google.inject.persist.Transactional) BigDecimal(java.math.BigDecimal) LeaveReasonRepository(com.axelor.apps.hr.db.repo.LeaveReasonRepository) TimesheetReminder(com.axelor.apps.hr.db.TimesheetReminder) Duration(java.time.Duration) Map(java.util.Map) EmployeeService(com.axelor.apps.hr.service.employee.EmployeeService) RoundingMode(java.math.RoundingMode) PublicHolidayService(com.axelor.apps.base.service.publicHoliday.PublicHolidayService) Set(java.util.Set) Message(com.axelor.apps.message.db.Message) TimesheetLine(com.axelor.apps.hr.db.TimesheetLine) Collectors(java.util.stream.Collectors) MessageService(com.axelor.apps.message.service.MessageService) List(java.util.List) Stream(java.util.stream.Stream) TimesheetRepository(com.axelor.apps.hr.db.repo.TimesheetRepository) LocalDate(java.time.LocalDate) TemporalAdjusters(java.time.temporal.TemporalAdjusters) Optional(java.util.Optional) LeaveService(com.axelor.apps.hr.service.leave.LeaveService) ExtraHoursRepository(com.axelor.apps.hr.db.repo.ExtraHoursRepository) LocalDateTime(java.time.LocalDateTime) HashMap(java.util.HashMap) TimesheetReminderLine(com.axelor.apps.hr.db.TimesheetReminderLine) ExtraHoursLineRepository(com.axelor.apps.hr.db.repo.ExtraHoursLineRepository) AppHumanResourceService(com.axelor.apps.hr.service.app.AppHumanResourceService) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) TimesheetLineRepository(com.axelor.apps.hr.db.repo.TimesheetLineRepository) TimesheetReport(com.axelor.apps.hr.db.TimesheetReport) AxelorException(com.axelor.exception.AxelorException) I18n(com.axelor.i18n.I18n) DateTool(com.axelor.apps.tool.date.DateTool) WeekFields(java.time.temporal.WeekFields) TraceBackRepository(com.axelor.exception.db.repo.TraceBackRepository) LeaveRequest(com.axelor.apps.hr.db.LeaveRequest) QueryBuilder(com.axelor.apps.tool.QueryBuilder) TraceBackService(com.axelor.exception.service.TraceBackService) TimesheetReminderRepository(com.axelor.apps.hr.db.repo.TimesheetReminderRepository) Template(com.axelor.apps.message.db.Template) DayPlanning(com.axelor.apps.base.db.DayPlanning) Beans(com.axelor.inject.Beans) WeeklyPlanningService(com.axelor.apps.base.service.weeklyplanning.WeeklyPlanningService) DayOfWeek(java.time.DayOfWeek) TemplateMessageService(com.axelor.apps.message.service.TemplateMessageService) User(com.axelor.auth.db.User) Employee(com.axelor.apps.hr.db.Employee) BigDecimal(java.math.BigDecimal)

Example 64 with AxelorException

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);
    }
}
Also used : ProjectPlanningTime(com.axelor.apps.project.db.ProjectPlanningTime) ProjectPlanningTimeRepository(com.axelor.apps.project.db.repo.ProjectPlanningTimeRepository) AxelorException(com.axelor.exception.AxelorException) Transactional(com.google.inject.persist.Transactional)

Example 65 with AxelorException

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);
    }
}
Also used : Message(com.axelor.apps.message.db.Message) Timesheet(com.axelor.apps.hr.db.Timesheet) MessageServiceBaseImpl(com.axelor.apps.base.service.message.MessageServiceBaseImpl) TimesheetService(com.axelor.apps.hr.service.timesheet.TimesheetService) AxelorException(com.axelor.exception.AxelorException)

Aggregations

AxelorException (com.axelor.exception.AxelorException)546 Transactional (com.google.inject.persist.Transactional)126 BigDecimal (java.math.BigDecimal)118 ArrayList (java.util.ArrayList)84 IOException (java.io.IOException)73 Product (com.axelor.apps.base.db.Product)64 Company (com.axelor.apps.base.db.Company)63 LocalDate (java.time.LocalDate)58 Partner (com.axelor.apps.base.db.Partner)48 List (java.util.List)45 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)40 HashMap (java.util.HashMap)38 Invoice (com.axelor.apps.account.db.Invoice)33 StockMove (com.axelor.apps.stock.db.StockMove)32 Map (java.util.Map)31 Beans (com.axelor.inject.Beans)30 I18n (com.axelor.i18n.I18n)28 Inject (com.google.inject.Inject)28 MoveLine (com.axelor.apps.account.db.MoveLine)27 Context (com.axelor.rpc.Context)27