use of com.axelor.apps.hr.db.HRConfig in project axelor-open-suite by axelor.
the class UserHrServiceImpl method createEmployee.
@Transactional
public void createEmployee(User user) {
if (user.getPartner() == null) {
Beans.get(UserService.class).createPartner(user);
}
AppBase appBase = appHumanResourceService.getAppBase();
AppLeave appLeave = appHumanResourceService.getAppLeave();
Employee employee = new Employee();
employee.setContactPartner(user.getPartner());
employee.setTimeLoggingPreferenceSelect(appBase.getTimeLoggingPreferenceSelect());
employee.setDailyWorkHours(appBase.getDailyWorkHours());
employee.setNegativeValueLeave(appLeave.getAllowNegativeLeaveEmployees());
EventsPlanning planning = null;
Company company = user.getActiveCompany();
if (company != null) {
HRConfig hrConfig = company.getHrConfig();
if (hrConfig != null) {
planning = hrConfig.getPublicHolidayEventsPlanning();
}
}
employee.setPublicHolidayEventsPlanning(planning);
employee.setUser(user);
Beans.get(EmployeeRepository.class).save(employee);
user.setEmployee(employee);
userRepo.save(user);
}
use of com.axelor.apps.hr.db.HRConfig in project axelor-open-suite by axelor.
the class UserHrServiceImpl method getTimesheetProduct.
@Override
public Product getTimesheetProduct(User user) {
if (user == null || user.getId() == null || user.getActiveCompany() == null) {
return null;
}
user = userRepo.find(user.getId());
Product product = null;
HRConfig hrConfig = user.getActiveCompany().getHrConfig();
if (hrConfig != null && hrConfig.getUseUniqueProductForTimesheet()) {
product = hrConfig.getUniqueTimesheetProduct();
}
if (product == null && user.getEmployee() != null) {
product = user.getEmployee().getProduct();
}
return product;
}
use of com.axelor.apps.hr.db.HRConfig in project axelor-open-suite by axelor.
the class EmployeeServiceImpl method getDaysWorksInPeriod.
@Override
public BigDecimal getDaysWorksInPeriod(Employee employee, LocalDate fromDate, LocalDate toDate) throws AxelorException {
Company company = employee.getMainEmploymentContract().getPayCompany();
BigDecimal duration = BigDecimal.ZERO;
WeeklyPlanning weeklyPlanning = employee.getWeeklyPlanning();
if (weeklyPlanning == null) {
HRConfig conf = company.getHrConfig();
if (conf != null) {
weeklyPlanning = conf.getWeeklyPlanning();
}
}
if (weeklyPlanning == null) {
throw new AxelorException(employee, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.EMPLOYEE_PLANNING), employee.getName());
}
EventsPlanning publicHolidayPlanning = employee.getPublicHolidayEventsPlanning();
if (publicHolidayPlanning == null) {
HRConfig conf = company.getHrConfig();
if (conf != null) {
publicHolidayPlanning = conf.getPublicHolidayEventsPlanning();
}
}
if (publicHolidayPlanning == null) {
throw new AxelorException(employee, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.EMPLOYEE_PUBLIC_HOLIDAY), employee.getName());
}
LocalDate date = fromDate;
while (!date.isAfter(toDate)) {
duration = duration.add(BigDecimal.valueOf(weeklyPlanningService.getWorkingDayValueInDays(weeklyPlanning, date)));
date = date.plusDays(1);
}
duration = duration.subtract(Beans.get(PublicHolidayHrService.class).computePublicHolidayDays(fromDate, toDate, weeklyPlanning, publicHolidayPlanning));
return duration;
}
use of com.axelor.apps.hr.db.HRConfig in project axelor-open-suite by axelor.
the class HumanResourceMobileController method insertKMExpenses.
/**
* This method is used in mobile application. It was in ExpenseController
*
* @param request
* @param response
* @throws AxelorException
* <p>POST
* /open-suite-webapp/ws/action/com.axelor.apps.hr.mobile.HumanResourceMobileController:insertKMExpenses
* Content-Type: application/json
* <p>URL: com.axelor.apps.hr.mobile.HumanResourceMobileController:insertKMExpenses fields:
* kmNumber, locationFrom, locationTo, allowanceTypeSelect, comments, date, projectTask,
* kilometricAllowParam
* <p>payload: { "data": { "action":
* "com.axelor.apps.hr.mobile.HumanResourceMobileController:insertKMExpenses", "kmNumber":
* 350.00, "locationFrom": "Paris", "locationTo": "Marseille", "allowanceTypeSelect": 1,
* "comments": "no", "date": "2018-02-22", "expenseProduct": 43 } }
*/
@Transactional(rollbackOn = { Exception.class })
public void insertKMExpenses(ActionRequest request, ActionResponse response) throws AxelorException {
User user = AuthUtils.getUser();
if (user != null) {
ExpenseService expenseService = Beans.get(ExpenseService.class);
Expense expense = expenseService.getOrCreateExpense(user);
ExpenseLine expenseLine = new ExpenseLine();
expenseLine.setDistance(new BigDecimal(request.getData().get("kmNumber").toString()));
expenseLine.setFromCity(request.getData().get("locationFrom").toString());
expenseLine.setToCity(request.getData().get("locationTo").toString());
expenseLine.setKilometricTypeSelect(new Integer(request.getData().get("allowanceTypeSelect").toString()));
expenseLine.setComments(request.getData().get("comments").toString());
expenseLine.setExpenseDate(LocalDate.parse(request.getData().get("date").toString()));
expenseLine.setProject(Beans.get(ProjectRepository.class).find(Long.valueOf(request.getData().get("projectTask").toString())));
HRConfigService hrConfigService = Beans.get(HRConfigService.class);
HRConfig hrConfig = hrConfigService.getHRConfig(expense.getCompany());
Product expenseProduct = hrConfigService.getKilometricExpenseProduct(hrConfig);
expenseLine.setExpenseProduct(expenseProduct);
Employee employee = user.getEmployee();
if (employee != null && !EmployeeHRRepository.isEmployeeFormerNewOrArchived(employee)) {
KilometricAllowParamRepository kilometricAllowParamRepo = Beans.get(KilometricAllowParamRepository.class);
expenseLine.setKilometricAllowParam(kilometricAllowParamRepo.find(Long.valueOf(request.getData().get("kilometricAllowParam").toString())));
expenseLine.setTotalAmount(Beans.get(KilometricService.class).computeKilometricExpense(expenseLine, employee));
expenseLine.setUntaxedAmount(expenseLine.getTotalAmount());
}
expense.addKilometricExpenseLineListItem(expenseLine);
Beans.get(ExpenseRepository.class).save(expense);
response.setValue("id", expenseLine.getId());
}
}
use of com.axelor.apps.hr.db.HRConfig in project axelor-open-suite by axelor.
the class PayrollPreparationService method exportNibelis.
public void exportNibelis(PayrollPreparation payrollPreparation, List<String[]> list) throws AxelorException {
HRConfig hrConfig = hrConfigService.getHRConfig(payrollPreparation.getCompany());
// LEAVES
if (payrollPreparation.getLeaveDuration().compareTo(BigDecimal.ZERO) > 0) {
List<PayrollLeave> payrollLeaveList = fillInLeaves(payrollPreparation);
for (PayrollLeave payrollLeave : payrollLeaveList) {
if (payrollLeave.getLeaveReason().getPayrollPreprationExport()) {
String[] leaveLine = createExportFileLine(payrollPreparation);
leaveLine[3] = payrollLeave.getLeaveReason().getExportCode();
leaveLine[4] = payrollLeave.getFromDate().format(DateTimeFormatter.ofPattern("dd/MM/yyyy"));
leaveLine[5] = payrollLeave.getToDate().format(DateTimeFormatter.ofPattern("dd/MM/yyyy"));
leaveLine[6] = payrollLeave.getDuration().toString();
list.add(leaveLine);
}
}
}
// LUNCH VOUCHER MANAGEMENT
if (payrollPreparation.getLunchVoucherNumber().compareTo(BigDecimal.ZERO) > 0) {
String[] lunchVoucherLine = createExportFileLine(payrollPreparation);
lunchVoucherLine[3] = hrConfig.getExportCodeForLunchVoucherManagement();
lunchVoucherLine[6] = payrollPreparation.getLunchVoucherNumber().toString();
list.add(lunchVoucherLine);
}
// EMPLOYEE BONUS MANAGEMENT
if (payrollPreparation.getEmployeeBonusAmount().compareTo(BigDecimal.ZERO) > 0) {
Map<String, BigDecimal> map = new HashMap<>();
for (EmployeeBonusMgtLine bonus : payrollPreparation.getEmployeeBonusMgtLineList()) {
if (bonus.getEmployeeBonusMgt().getEmployeeBonusType().getPayrollPreparationExport()) {
if (map.containsKey(bonus.getEmployeeBonusMgt().getEmployeeBonusType().getExportCode())) {
map.put(bonus.getEmployeeBonusMgt().getEmployeeBonusType().getExportCode(), bonus.getAmount().add(map.get(bonus.getEmployeeBonusMgt().getEmployeeBonusType().getExportCode())));
} else {
map.put(bonus.getEmployeeBonusMgt().getEmployeeBonusType().getExportCode(), bonus.getAmount());
}
}
}
for (Map.Entry<String, BigDecimal> entry : map.entrySet()) {
String[] employeeBonusLine = createExportFileLine(payrollPreparation);
employeeBonusLine[3] = entry.getKey();
employeeBonusLine[6] = entry.getValue().toString();
list.add(employeeBonusLine);
}
}
// EXTRA HOURS
if (payrollPreparation.getExtraHoursNumber().compareTo(BigDecimal.ZERO) > 0) {
List<ExtraHoursLine> extraHourLineList = Beans.get(ExtraHoursLineRepository.class).all().filter("self.payrollPreparation.id = ?1" + " AND self.extraHoursType.payrollPreprationExport = ?2", payrollPreparation.getId(), true).fetch();
Map<ExtraHoursType, BigDecimal> extraHourLineExportMap = extraHourLineList.stream().collect(Collectors.groupingBy(ExtraHoursLine::getExtraHoursType, Collectors.reducing(BigDecimal.ZERO, ExtraHoursLine::getQty, BigDecimal::add)));
extraHourLineExportMap.forEach((extraHoursTypeGroup, totalHours) -> {
String[] extraHourLine = createExportFileLine(payrollPreparation);
extraHourLine[3] = extraHoursTypeGroup.getExportCode();
extraHourLine[6] = totalHours.toString();
list.add(extraHourLine);
});
}
}
Aggregations