Search in sources :

Example 1 with LunchVoucherAdvance

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

the class LunchVoucherAdvanceController method onNewAdvance.

public void onNewAdvance(ActionRequest request, ActionResponse response) {
    LunchVoucherAdvance lunchVoucherAdvance = EntityHelper.getEntity(request.getContext().asType(LunchVoucherAdvance.class));
    try {
        Beans.get(LunchVoucherAdvanceService.class).onNewAdvance(lunchVoucherAdvance);
        response.setCanClose(true);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : LunchVoucherAdvance(com.axelor.apps.hr.db.LunchVoucherAdvance) LunchVoucherAdvanceService(com.axelor.apps.hr.service.lunch.voucher.LunchVoucherAdvanceService) AxelorException(com.axelor.exception.AxelorException)

Example 2 with LunchVoucherAdvance

use of com.axelor.apps.hr.db.LunchVoucherAdvance 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 3 with LunchVoucherAdvance

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

the class LunchVoucherAdvanceController method print.

public void print(ActionRequest request, ActionResponse response) {
    LunchVoucherAdvance lunchVoucherAdvance = request.getContext().asType(LunchVoucherAdvance.class);
    String name = lunchVoucherAdvance.getEmployee().getName() + "-" + Beans.get(AppBaseService.class).getTodayDate(Optional.ofNullable(lunchVoucherAdvance.getEmployee()).map(Employee::getUser).map(User::getActiveCompany).orElse(Optional.ofNullable(AuthUtils.getUser()).map(User::getActiveCompany).orElse(null))).format(DateTimeFormatter.ISO_DATE);
    try {
        String fileLink = ReportFactory.createReport(IReport.LUNCH_VOUCHER_ADVANCE, name).addParam("lunchVoucherAdvId", lunchVoucherAdvance.getId()).addParam("Timezone", getTimezone(lunchVoucherAdvance)).addFormat(ReportSettings.FORMAT_PDF).generate().getFileLink();
        response.setView(ActionView.define(name).add("html", fileLink).map());
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : LunchVoucherAdvance(com.axelor.apps.hr.db.LunchVoucherAdvance) User(com.axelor.auth.db.User) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) AxelorException(com.axelor.exception.AxelorException)

Example 4 with LunchVoucherAdvance

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

the class LunchVoucherMgtLineServiceImpl method computeEmployeeLunchVoucherAdvance.

private Integer computeEmployeeLunchVoucherAdvance(Employee employee) {
    int number = 0;
    List<LunchVoucherAdvance> list = Beans.get(LunchVoucherAdvanceRepository.class).all().filter("self.employee.id = ?1 AND self.nbrLunchVouchersUsed < self.nbrLunchVouchers", employee.getId()).fetch();
    for (LunchVoucherAdvance item : list) {
        number += item.getNbrLunchVouchers() - item.getNbrLunchVouchersUsed();
    }
    return number;
}
Also used : LunchVoucherAdvance(com.axelor.apps.hr.db.LunchVoucherAdvance) LunchVoucherAdvanceRepository(com.axelor.apps.hr.db.repo.LunchVoucherAdvanceRepository)

Aggregations

LunchVoucherAdvance (com.axelor.apps.hr.db.LunchVoucherAdvance)4 AxelorException (com.axelor.exception.AxelorException)2 Company (com.axelor.apps.base.db.Company)1 AppBaseService (com.axelor.apps.base.service.app.AppBaseService)1 HRConfig (com.axelor.apps.hr.db.HRConfig)1 LunchVoucherAdvanceRepository (com.axelor.apps.hr.db.repo.LunchVoucherAdvanceRepository)1 HRConfigService (com.axelor.apps.hr.service.config.HRConfigService)1 LunchVoucherAdvanceService (com.axelor.apps.hr.service.lunch.voucher.LunchVoucherAdvanceService)1 LunchVoucherMgtService (com.axelor.apps.hr.service.lunch.voucher.LunchVoucherMgtService)1 User (com.axelor.auth.db.User)1