Search in sources :

Example 11 with HRConfig

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);
}
Also used : EmployeeRepository(com.axelor.apps.hr.db.repo.EmployeeRepository) Company(com.axelor.apps.base.db.Company) Employee(com.axelor.apps.hr.db.Employee) HRConfig(com.axelor.apps.hr.db.HRConfig) UserService(com.axelor.apps.base.service.user.UserService) AppLeave(com.axelor.apps.base.db.AppLeave) EventsPlanning(com.axelor.apps.base.db.EventsPlanning) AppBase(com.axelor.apps.base.db.AppBase) Transactional(com.google.inject.persist.Transactional)

Example 12 with HRConfig

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;
}
Also used : HRConfig(com.axelor.apps.hr.db.HRConfig) Product(com.axelor.apps.base.db.Product)

Example 13 with HRConfig

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;
}
Also used : AxelorException(com.axelor.exception.AxelorException) Company(com.axelor.apps.base.db.Company) HRConfig(com.axelor.apps.hr.db.HRConfig) EventsPlanning(com.axelor.apps.base.db.EventsPlanning) PublicHolidayHrService(com.axelor.apps.hr.service.publicHoliday.PublicHolidayHrService) WeeklyPlanning(com.axelor.apps.base.db.WeeklyPlanning) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal)

Example 14 with HRConfig

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());
    }
}
Also used : User(com.axelor.auth.db.User) Employee(com.axelor.apps.hr.db.Employee) HRConfig(com.axelor.apps.hr.db.HRConfig) Expense(com.axelor.apps.hr.db.Expense) KilometricAllowParamRepository(com.axelor.apps.hr.db.repo.KilometricAllowParamRepository) ExpenseRepository(com.axelor.apps.hr.db.repo.ExpenseRepository) ExpenseService(com.axelor.apps.hr.service.expense.ExpenseService) HRConfigService(com.axelor.apps.hr.service.config.HRConfigService) Product(com.axelor.apps.base.db.Product) ExpenseLine(com.axelor.apps.hr.db.ExpenseLine) BigDecimal(java.math.BigDecimal) Transactional(com.google.inject.persist.Transactional)

Example 15 with HRConfig

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);
        });
    }
}
Also used : HashMap(java.util.HashMap) ExtraHoursType(com.axelor.apps.hr.db.ExtraHoursType) ExtraHoursLine(com.axelor.apps.hr.db.ExtraHoursLine) BigDecimal(java.math.BigDecimal) HRConfig(com.axelor.apps.hr.db.HRConfig) EmployeeBonusMgtLine(com.axelor.apps.hr.db.EmployeeBonusMgtLine) ExtraHoursLineRepository(com.axelor.apps.hr.db.repo.ExtraHoursLineRepository) PayrollLeave(com.axelor.apps.hr.db.PayrollLeave) HashMap(java.util.HashMap) Map(java.util.Map)

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