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