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));
}
}
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));
}
}
}
}
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;
}
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());
}
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;
}
Aggregations