Search in sources :

Example 1 with HRConfig

use of com.axelor.apps.hr.db.HRConfig in project axelor-open-suite by axelor.

the class LunchVoucherAdvanceController method checkOnNewAdvance.

public void checkOnNewAdvance(ActionRequest request, ActionResponse response) throws AxelorException {
    LunchVoucherAdvance lunchVoucherAdvance = EntityHelper.getEntity(request.getContext().asType(LunchVoucherAdvance.class));
    if (lunchVoucherAdvance.getEmployee().getMainEmploymentContract() == null) {
        response.setError(String.format(I18n.get(IExceptionMessage.EMPLOYEE_CONTRACT_OF_EMPLOYMENT), lunchVoucherAdvance.getEmployee().getName()));
        return;
    }
    Company company = lunchVoucherAdvance.getEmployee().getMainEmploymentContract().getPayCompany();
    HRConfig hrConfig = Beans.get(HRConfigService.class).getHRConfig(company);
    int stock = Beans.get(LunchVoucherMgtService.class).checkStock(company, lunchVoucherAdvance.getNbrLunchVouchers());
    if (stock <= 0) {
        response.setAlert(String.format(I18n.get(IExceptionMessage.LUNCH_VOUCHER_MIN_STOCK), company.getName(), hrConfig.getMinStockLunchVoucher(), hrConfig.getAvailableStockLunchVoucher(), TraceBackRepository.CATEGORY_INCONSISTENCY));
    }
}
Also used : LunchVoucherAdvance(com.axelor.apps.hr.db.LunchVoucherAdvance) Company(com.axelor.apps.base.db.Company) HRConfig(com.axelor.apps.hr.db.HRConfig) HRConfigService(com.axelor.apps.hr.service.config.HRConfigService) LunchVoucherMgtService(com.axelor.apps.hr.service.lunch.voucher.LunchVoucherMgtService)

Example 2 with HRConfig

use of com.axelor.apps.hr.db.HRConfig in project axelor-open-suite by axelor.

the class TimesheetServiceImpl method prefillLines.

@Override
public void prefillLines(Timesheet timesheet) throws AxelorException {
    PublicHolidayService holidayService = Beans.get(PublicHolidayService.class);
    LeaveService leaveService = Beans.get(LeaveService.class);
    WeeklyPlanningService weeklyPlanningService = Beans.get(WeeklyPlanningService.class);
    AppTimesheet appTimesheet = appHumanResourceService.getAppTimesheet();
    LocalDate fromDate = timesheet.getFromDate();
    LocalDate toDate = timesheet.getToDate();
    User user = timesheet.getUser();
    Employee employee = user.getEmployee();
    HRConfig config = timesheet.getCompany().getHrConfig();
    WeeklyPlanning weeklyPlanning = employee != null ? employee.getWeeklyPlanning() : config.getWeeklyPlanning();
    EventsPlanning holidayPlanning = employee != null ? employee.getPublicHolidayEventsPlanning() : config.getPublicHolidayEventsPlanning();
    for (LocalDate date = fromDate; !date.isAfter(toDate); date = date.plusDays(1)) {
        BigDecimal dayValueInHours = weeklyPlanningService.getWorkingDayValueInHours(weeklyPlanning, date, LocalTime.MIN, LocalTime.MAX);
        if (appTimesheet.getCreateLinesForHolidays() && holidayService.checkPublicHolidayDay(date, holidayPlanning)) {
            timesheetLineService.createTimesheetLine(user, date, timesheet, dayValueInHours, I18n.get(IExceptionMessage.TIMESHEET_HOLIDAY));
        } else if (appTimesheet.getCreateLinesForLeaves()) {
            List<LeaveRequest> leaveList = leaveService.getLeaves(user, date);
            BigDecimal totalLeaveHours = BigDecimal.ZERO;
            if (ObjectUtils.notEmpty(leaveList)) {
                for (LeaveRequest leave : leaveList) {
                    BigDecimal leaveHours = leaveService.computeDuration(leave, date, date);
                    if (leave.getLeaveReason().getUnitSelect() == LeaveReasonRepository.UNIT_SELECT_DAYS) {
                        leaveHours = leaveHours.multiply(dayValueInHours);
                    }
                    totalLeaveHours = totalLeaveHours.add(leaveHours);
                }
                timesheetLineService.createTimesheetLine(user, date, timesheet, totalLeaveHours, I18n.get(IExceptionMessage.TIMESHEET_DAY_LEAVE));
            }
        }
    }
}
Also used : User(com.axelor.auth.db.User) EventsPlanning(com.axelor.apps.base.db.EventsPlanning) WeeklyPlanning(com.axelor.apps.base.db.WeeklyPlanning) LeaveRequest(com.axelor.apps.hr.db.LeaveRequest) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) AppTimesheet(com.axelor.apps.base.db.AppTimesheet) Employee(com.axelor.apps.hr.db.Employee) HRConfig(com.axelor.apps.hr.db.HRConfig) LeaveService(com.axelor.apps.hr.service.leave.LeaveService) WeeklyPlanningService(com.axelor.apps.base.service.weeklyplanning.WeeklyPlanningService) List(java.util.List) PriceList(com.axelor.apps.base.db.PriceList) ArrayList(java.util.ArrayList) PublicHolidayService(com.axelor.apps.base.service.publicHoliday.PublicHolidayService)

Example 3 with HRConfig

use of com.axelor.apps.hr.db.HRConfig in project axelor-open-suite by axelor.

the class TimesheetServiceImpl method sendCancellationEmail.

@Override
@Transactional(rollbackOn = { Exception.class })
public Message sendCancellationEmail(Timesheet timesheet) throws AxelorException, ClassNotFoundException, InstantiationException, IllegalAccessException, MessagingException, IOException, JSONException {
    HRConfig hrConfig = hrConfigService.getHRConfig(timesheet.getCompany());
    Template template = hrConfig.getCanceledTimesheetTemplate();
    if (hrConfig.getTimesheetMailNotification() && template != null) {
        return templateMessageService.generateAndSendMessage(timesheet, template);
    }
    return null;
}
Also used : HRConfig(com.axelor.apps.hr.db.HRConfig) Template(com.axelor.apps.message.db.Template) Transactional(com.google.inject.persist.Transactional)

Example 4 with HRConfig

use of com.axelor.apps.hr.db.HRConfig in project axelor-open-suite by axelor.

the class ExpenseServiceImpl method setExpenseSeq.

private void setExpenseSeq(Expense expense) throws AxelorException {
    if (!Beans.get(SequenceService.class).isEmptyOrDraftSequenceNumber(expense.getExpenseSeq())) {
        return;
    }
    HRConfig hrConfig = hrConfigService.getHRConfig(expense.getCompany());
    Sequence sequence = hrConfigService.getExpenseSequence(hrConfig);
    if (sequence != null) {
        expense.setExpenseSeq(Beans.get(SequenceService.class).getSequenceNumber(sequence, expense.getSentDate()));
        if (expense.getExpenseSeq() != null) {
            return;
        }
    }
    throw new AxelorException(expense, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.HR_CONFIG_NO_EXPENSE_SEQUENCE), expense.getCompany().getName());
}
Also used : AxelorException(com.axelor.exception.AxelorException) HRConfig(com.axelor.apps.hr.db.HRConfig) Sequence(com.axelor.apps.base.db.Sequence)

Example 5 with HRConfig

use of com.axelor.apps.hr.db.HRConfig in project axelor-open-suite by axelor.

the class PayrollPreparationService method exportSilae.

public List<String[]> exportSilae(PayrollPreparation payrollPrep, List<String[]> exportLineList) throws AxelorException {
    HRConfig hrConfig = hrConfigService.getHRConfig(payrollPrep.getCompany());
    // Payroll leaves
    if (payrollPrep.getLeaveDuration().compareTo(BigDecimal.ZERO) > 0) {
        List<PayrollLeave> payrollLeaveList = this.fillInLeaves(payrollPrep);
        for (PayrollLeave payrollLeave : payrollLeaveList) {
            if (payrollLeave.getLeaveReason().getPayrollPreprationExport()) {
                String[] leaveLine = createSilaeExportFileLine(payrollPrep);
                leaveLine[1] = payrollLeave.getLeaveReason().getExportCode();
                leaveLine[2] = String.valueOf(payrollLeave.getDuration());
                leaveLine[3] = payrollLeave.getFromDate().format(DateTimeFormatter.ofPattern("dd/MM/yyyy"));
                leaveLine[4] = payrollLeave.getToDate().format(DateTimeFormatter.ofPattern("dd/MM/yyyy"));
                exportLineList.add(leaveLine);
            }
        }
    }
    // Payroll duration
    String[] durationLine = createSilaeExportFileLine(payrollPrep);
    durationLine[1] = hrConfig.getExportCodeForDuration();
    durationLine[2] = String.valueOf(payrollPrep.getDuration());
    exportLineList.add(durationLine);
    // Payroll extraHoursNumber
    String[] extraHoursLine = createSilaeExportFileLine(payrollPrep);
    extraHoursLine[1] = hrConfig.getExportCodeForExtraHours();
    extraHoursLine[2] = String.valueOf(payrollPrep.getExtraHoursNumber());
    exportLineList.add(extraHoursLine);
    return exportLineList;
}
Also used : HRConfig(com.axelor.apps.hr.db.HRConfig) PayrollLeave(com.axelor.apps.hr.db.PayrollLeave)

Aggregations

HRConfig (com.axelor.apps.hr.db.HRConfig)16 Transactional (com.google.inject.persist.Transactional)8 Company (com.axelor.apps.base.db.Company)5 Template (com.axelor.apps.message.db.Template)4 BigDecimal (java.math.BigDecimal)4 EventsPlanning (com.axelor.apps.base.db.EventsPlanning)3 Employee (com.axelor.apps.hr.db.Employee)3 HRConfigService (com.axelor.apps.hr.service.config.HRConfigService)3 Product (com.axelor.apps.base.db.Product)2 WeeklyPlanning (com.axelor.apps.base.db.WeeklyPlanning)2 PayrollLeave (com.axelor.apps.hr.db.PayrollLeave)2 User (com.axelor.auth.db.User)2 AxelorException (com.axelor.exception.AxelorException)2 LocalDate (java.time.LocalDate)2 AppBase (com.axelor.apps.base.db.AppBase)1 AppLeave (com.axelor.apps.base.db.AppLeave)1 AppTimesheet (com.axelor.apps.base.db.AppTimesheet)1 PriceList (com.axelor.apps.base.db.PriceList)1 Sequence (com.axelor.apps.base.db.Sequence)1 PublicHolidayService (com.axelor.apps.base.service.publicHoliday.PublicHolidayService)1