private T getAttrRowForCurrentDate(final List<T> attrRows) { return timeableService.getAttrRowValidAtDate(attrRows, attrGroup, new Date()); }
@Override public BigDecimal getMonthlySalary(EmployeeDO employee, Calendar selectedDate) { final EmployeeTimedDO attribute = timeableService.getAttrRowValidAtDate(employee, "annuity", selectedDate.getTime()); final BigDecimal annualSalary = attribute != null ? attribute.getAttribute("annuity", BigDecimal.class) : null; final BigDecimal weeklyWorkingHours = employee.getWeeklyWorkingHours(); if (annualSalary != null && weeklyWorkingHours != null && BigDecimal.ZERO.compareTo(weeklyWorkingHours) < 0) { // do the multiplication before the division to minimize rounding problems // we need a rounding mode to avoid ArithmeticExceptions when the exact result cannot be represented in the result return annualSalary .multiply(weeklyWorkingHours) .divide(MONTHS_PER_YEAR, BigDecimal.ROUND_HALF_UP) .divide(FULL_TIME_WEEKLY_WORKING_HOURS, BigDecimal.ROUND_HALF_UP); } return null; }
@Override public EmployeeStatus getEmployeeStatus(final EmployeeDO employee) { final EmployeeTimedDO attrRow = timeableService .getAttrRowValidAtDate(employee, InternalAttrSchemaConstants.EMPLOYEE_STATUS_GROUP_NAME, new Date()); if (attrRow != null && StringUtils.isEmpty(attrRow.getStringAttribute(InternalAttrSchemaConstants.EMPLOYEE_STATUS_DESC_NAME)) == false) { return EmployeeStatus.findByi18nKey(attrRow.getStringAttribute(InternalAttrSchemaConstants.EMPLOYEE_STATUS_DESC_NAME)); } return null; }
@Override public boolean isFulltimeEmployee(final EmployeeDO employee, final Calendar selectedDate) { final Calendar date = (Calendar) selectedDate.clone(); // create a clone to avoid changing the original object final Date startOfMonth = date.getTime(); date.add(Calendar.MONTH, 1); date.add(Calendar.DATE, -1); final Date endOfMonth = date.getTime(); final List<EmployeeTimedDO> attrRows = timeableService .getAttrRowsWithinDateRange(employee, InternalAttrSchemaConstants.EMPLOYEE_STATUS_GROUP_NAME, startOfMonth, endOfMonth); final EmployeeTimedDO rowValidAtBeginOfMonth = timeableService .getAttrRowValidAtDate(employee, InternalAttrSchemaConstants.EMPLOYEE_STATUS_GROUP_NAME, selectedDate.getTime()); if (rowValidAtBeginOfMonth != null) { attrRows.add(rowValidAtBeginOfMonth); } return attrRows .stream() .map(row -> row.getStringAttribute(InternalAttrSchemaConstants.EMPLOYEE_STATUS_DESC_NAME)) .filter(Objects::nonNull) .anyMatch(s -> EmployeeStatus.FEST_ANGESTELLTER.getI18nKey().equals(s) || EmployeeStatus.BEFRISTET_ANGESTELLTER.getI18nKey().equals(s)); }
@Override public <PK extends Serializable, T extends TimeableAttrRow<PK>, U extends EntityWithTimeableAttr<PK, T> & EntityWithConfigurableAttr> Optional<IModel<String>> getStringAttribute(final U entity, final Date date, final String groupName, final String descName) { final T attrRowForCurrentDate = timeableService.getAttrRowValidAtDate(entity, groupName, date); if (attrRowForCurrentDate == null) { return Optional.empty(); } final String attribute = attrRowForCurrentDate.getStringAttribute(descName); if (attribute == null) { return Optional.empty(); } final AttrDescription attrDescription = getAttrDescription(entity, groupName, descName); final IModel<String> valueModel = (attrDescription.getWicketComponentFactoryClass() instanceof DropDownAttrWicketComponentFactory) ? new ResourceModel(attribute) : // DropDownAttrWicketComponentFactory -> it's a list of i18nkeys, so we need a ResourceModel for the translation new Model<>(attribute); return Optional.of(valueModel); }