Skip to content

Commit

Permalink
Merge branch 'main' into
Browse files Browse the repository at this point in the history
272-nella-form-di-inserimento-assenza-togliere-la-parola-assenza
  • Loading branch information
Dario Tagliaferri committed Nov 21, 2024
2 parents a2d7703 + 969275d commit b3a7885
Show file tree
Hide file tree
Showing 51 changed files with 2,126 additions and 288 deletions.
7 changes: 4 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [2.20.2] - 2024-11-18
### Added
- Aggiunto codice 54TD - Aspettativa Legge Gelmini
- Aggiunto flusso di richiesta straordinari

### Changed
- Rimossa validazione dati della persona nell'inserimento di un nuovo badge
Expand Down Expand Up @@ -226,17 +227,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [2.9.0] - 2023-11-06
### Added
- Gestione delle richieste di straordinario da parte del personale IV-VIII, con possibilità
- Gestione delle richieste di straordinario da parte del personale IV-VIII, con possibilità
di configurare richieste preventive e consuntive di straordinario ed approvazione da parte
del responsabile di gruppo e/o di sede.
- Aggiornata immagine docker con tag stable su ghcr.io per ogni nuova release

### Changed
- Evitati di caricare tutti i contratti presenti nel sistema nella visualizzazione delle
sedi senza personale
- Evitati di caricare tutti i contratti presenti nel sistema nella visualizzazione delle sedi senza personale
- Permesso al ruolo "ADMIN" di effettuare le operazioni sulle assenze
- Permesso al ruolo "RO_ADMIN" di scaricare gli allegati delle assenze


## [2.8.0] - 2023-09-15
### Added
- Gestito invio segnalazioni anonime ad epas-helpdesk-service.
Expand Down
288 changes: 234 additions & 54 deletions app/controllers/CompetenceRequests.java

Large diffs are not rendered by default.

32 changes: 28 additions & 4 deletions app/controllers/Competences.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import dao.CertificationDao;
import dao.CompetenceCodeDao;
import dao.CompetenceDao;
import dao.GeneralSettingDao;
import dao.MonthlyCompetenceTypeDao;
import dao.OfficeDao;
import dao.OrganizationShiftTimeTableDao;
Expand Down Expand Up @@ -60,6 +61,8 @@
import manager.ConsistencyManager;
import manager.ShiftOrganizationManager;
import manager.competences.ShiftTimeTableDto;
import manager.configurations.ConfigurationManager;
import manager.configurations.EpasParam;
import manager.recaps.competence.CompetenceRecap;
import manager.recaps.competence.CompetenceRecapFactory;
import manager.recaps.competence.PersonMonthCompetenceRecap;
Expand All @@ -72,6 +75,7 @@
import models.CompetenceCode;
import models.CompetenceCodeGroup;
import models.Contract;
import models.GeneralSetting;
import models.MonthlyCompetenceType;
import models.Office;
import models.OrganizationShiftTimeTable;
Expand Down Expand Up @@ -149,7 +153,10 @@ public class Competences extends Controller {
private static OrganizationShiftTimeTableDao shiftTimeTableDao;
@Inject
private static MonthlyCompetenceTypeDao monthlyDao;

@Inject
private static ConfigurationManager configurationManager;
@Inject
private static GeneralSettingDao settingDao;

/**
* Crud CompetenceCode.
Expand Down Expand Up @@ -639,11 +646,28 @@ public static void totalOvertimeHours(int year, Long officeId) {
notFoundIfNull(office);

rules.checkIfPermitted(office);

/* Recupero le info per le ore del monte ore straordinari per la sede*/
List<TotalOvertime> totalList = competenceDao.getTotalOvertime(year, office);
int totale = competenceManager.getTotalOvertime(totalList);

render(totalList, totale, year, office);

/* Recupero la lista degli abilitati allo straordinario per assegnargli le ore di
monte ore personale (previa verifica del parametro associato)
*/
List<Person> personList = Lists.newArrayList();
GeneralSetting settings = settingDao.generalSetting();
if (!settings.isEnableOvertimePerPerson()) {
log.warn("Non abilitato il parametro per gli straordinari per persona!!");
} else {
CompetenceCode code = competenceCodeDao.getCompetenceCodeByCode("S1");
Set<Office> offices = Sets.newHashSet();
offices.add(office);
personList = personDao
.listForCompetence(code, Optional.absent(), offices, true,
LocalDate.now().withYear(year).monthOfYear().withMinimumValue()
.dayOfMonth().withMinimumValue(), LocalDate.now(), Optional.absent()).list();
}

render(totalList, totale, year, office, personList);
}

/**
Expand Down
74 changes: 74 additions & 0 deletions app/controllers/GroupOvertimes.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Copyright (C) 2023 Consiglio Nazionale delle Ricerche
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package controllers;

import com.google.common.collect.Maps;
import common.security.SecurityRules;
import java.util.List;
import java.util.Map;
import javax.inject.Inject;
import org.joda.time.LocalDate;
import dao.CompetenceCodeDao;
import dao.CompetenceDao;
import dao.GroupDao;
import manager.GroupOvertimeManager;
import models.Competence;
import models.CompetenceCode;
import models.GroupOvertime;
import models.Person;
import models.User;
import models.flows.Group;
import play.data.validation.Equals;
import play.data.validation.Required;
import play.data.validation.Valid;
import play.mvc.Controller;
import play.mvc.With;

@With({Resecure.class})
public class GroupOvertimes extends Controller {

@Inject
private static GroupOvertimeManager groupOvertimeManager;
@Inject
private static GroupDao groupDao;
@Inject
private static SecurityRules rules;

public static void save(int year, GroupOvertime groupOvertime, Long groupId) {

Group group = groupDao.byId(groupId).get();
notFoundIfNull(group);
rules.checkIfPermitted(group.getOffice());
if (!groupOvertime.getNumberOfHours().toString().matches("\\d+")) {
flash.error("Inserire una cifra e non delle lettere");
Groups.handleOvertimeGroup(group.getId());
}
groupOvertime.setGroup(group);
if (groupOvertimeManager.checkOvertimeAvailability(groupOvertime, year)) {
groupOvertime.setDateOfUpdate(LocalDate.now());
groupOvertime.setYear(year);
groupOvertime.save();
flash.success("Aggiunta quantità di ore di straordinario per il gruppo %s", group.getName());
} else {
flash.error("La quantità che si intende inserire fa superare il limite di ore disponibili!!");
}

Groups.handleOvertimeGroup(group.getId());
}

}
126 changes: 125 additions & 1 deletion app/controllers/Groups.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,19 @@
package controllers;


import com.google.common.base.Functions;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableSortedMap;
import com.google.common.collect.Lists;
import com.google.common.collect.Ordering;
import common.security.SecurityRules;
import dao.CompetenceDao;
import dao.GeneralSettingDao;
import dao.GroupDao;
import dao.GroupOvertimeDao;
import dao.OfficeDao;
import dao.PersonDao;
import dao.PersonOvertimeDao;
import dao.RoleDao;
import dao.UsersRolesOfficesDao;
import helpers.Web;
Expand All @@ -32,19 +39,27 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import javax.inject.Inject;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import manager.CompetenceManager;
import manager.GroupManager;
import manager.GroupOvertimeManager;
import manager.configurations.ConfigurationManager;
import manager.configurations.EpasParam;
import models.GeneralSetting;
import models.GroupOvertime;
import models.Office;
import models.Person;
import models.PersonOvertime;
import models.Role;
import models.TotalOvertime;
import models.User;
import models.UsersRolesOffices;
import models.dto.PersonOvertimeInMonth;
import models.flows.Group;
import org.testng.collections.Lists;
import org.testng.util.Strings;
import play.data.binding.As;
import play.data.validation.Valid;
Expand Down Expand Up @@ -75,6 +90,18 @@ public class Groups extends Controller {
private static UsersRolesOfficesDao uroDao;
@Inject
private static RoleDao roleDao;
@Inject
private static CompetenceDao competenceDao;
@Inject
private static CompetenceManager competenceManager;
@Inject
private static GroupOvertimeDao groupOvertimeDao;
@Inject
private static GroupOvertimeManager groupOvertimeManager;
@Inject
private static ConfigurationManager configurationManager;
@Inject
private static PersonOvertimeDao personOvertimeDao;

/**
* Metodo che crea il gruppo.
Expand Down Expand Up @@ -166,6 +193,8 @@ public static void showGroups(Long officeId) {
}
if (user.isSystemUser()
|| uroDao.getUsersRolesOffices(user, roleDao.getRoleByName(Role.PERSONNEL_ADMIN), office)
.isPresent()
|| uroDao.getUsersRolesOffices(user, roleDao.getRoleByName(Role.SEAT_SUPERVISOR), office)
.isPresent()) {
groups = groupDao.groupsByOffice(office, Optional.<Person>absent(), Optional.of(true));
}
Expand Down Expand Up @@ -252,6 +281,101 @@ public static void viewInfoRole(Long id) {
Role role = roleDao.getRoleById(id);
render(role);
}

/**
* Ritorna la pagina di gestione delle ore di straordinario da associare al gruppo.
* @param groupId l'identificativo del gruppo
*/
public static void handleOvertimeGroup(Long groupId) {
Group group = Group.findById(groupId);
notFoundIfNull(group);
rules.checkIfPermitted(group.getOffice());
//La quantità di ore di straordinario accordate al gruppo nell'anno
int year = LocalDate.now().getYear();
int totalGroupOvertimes = group.getGroupOvertimes().stream()
.filter(go -> go.getYear().equals(year))
.mapToInt(go -> go.getNumberOfHours()).sum();
//Recupero il monte ore della sede decurtandolo di eventuali assegnamenti ad atri gruppi
List<TotalOvertime> totalList = competenceDao
.getTotalOvertime(LocalDate.now().getYear(), group.getOffice());
int totale = competenceManager.getTotalOvertime(totalList);
List<Group> groupList = group.getOffice().getGroups().stream()
.filter(g -> !g.getName().equals(group.getName())).collect(Collectors.toList());
int groupOvertimeSum = 0;
for (Group otherGroup : groupList) {
List<GroupOvertime> groupOvertimeList = groupOvertimeDao
.getByYearAndGroup(year, otherGroup);
groupOvertimeSum = groupOvertimeSum + groupOvertimeList.stream()
.mapToInt(go -> go.getNumberOfHours()).sum();
}
Map<Integer, List<PersonOvertimeInMonth>> mapFirst =
groupOvertimeManager.groupOvertimeSituationInYear(group.getPeople(),
year);
Ordering naturalOrderingDesc = Ordering.natural().reverse();
Map<Integer, List<PersonOvertimeInMonth>> map =
ImmutableSortedMap.copyOf(mapFirst, naturalOrderingDesc);
int overtimeAssigned = groupOvertimeManager.groupOvertimeAssignedInYear(mapFirst);
int groupOvertimesAvailable = totalGroupOvertimes - overtimeAssigned;
int hoursAvailable = totale - totalGroupOvertimes - groupOvertimeSum;
Office office = group.getOffice();
GroupOvertime groupOvertime = new GroupOvertime();
List<GroupOvertime> groupOvertimeInYearList = group.getGroupOvertimes().stream()
.filter(go -> go.getYear().equals(year)).collect(Collectors.toList());
GeneralSetting settings = settingDao.generalSetting();
boolean check = settings.isEnableOvertimePerPerson();
render(group, totalGroupOvertimes, office, groupOvertime, hoursAvailable, map,
groupOvertimesAvailable, groupOvertimeInYearList, year, check, totale);
}

public static void addHours(Long personId, int year) {

Person person = personDao.getPersonById(personId);
notFoundIfNull(person);
rules.checkIfPermitted(person.getOffice());
List<PersonOvertime> personOvertimes = personOvertimeDao.personListInYear(person, year);
PersonOvertime personOvertime = new PersonOvertime();
render(personOvertimes, person, year, personOvertime);
}

public static void saveHours(PersonOvertime personOvertime,
int year, Long personId) {
Person person = personDao.getPersonById(personId);
notFoundIfNull(person);
rules.checkIfPermitted(person.getOffice());
Pattern pattern = Pattern.compile("-?\\d+(\\.\\d+)?");

if (personOvertime.getNumberOfHours() == null
|| !pattern.matcher(personOvertime.getNumberOfHours().toString()).matches()) {
Validation.addError("personOvertime.getNumberOfHours", "Inserire una quantità numerica!");
}
if (personOvertime.getDateOfUpdate() == null) {
Validation.addError("personOvertime.dateOfUpdate", "Inserire una data valida!!");
}
if (personOvertime.getDateOfUpdate().getYear() != year) {
Validation.addError("personOvertime.dateOfUpdate",
"Si sta inserendo una quantità per un anno diverso da quello specificato nella data!!");
}
int totalOvertimes = 0;
List<GroupOvertime> list = person.getGroups().stream().flatMap(g -> g.getGroupOvertimes().stream()
.filter(go -> go.getYear().equals(LocalDate.now().getYear())))
.collect(Collectors.toList());
totalOvertimes = list.stream().mapToInt(go -> go.getNumberOfHours()).sum();
if (personOvertime.getNumberOfHours() > totalOvertimes) {
Validation.addError("personOvertime.numberOfHours",
"Si sta inserendo una quantità che supera il limite massimo di ore previste "
+ "dalla propria configurazione. Aggiungere monte ore al gruppo o alla sede!");
}
if (Validation.hasErrors()) {
response.status = 400;
render("@addHours", person, year, personOvertime);
}
personOvertime.setPerson(person);
personOvertime.setYear(year);
personOvertime.save();
flash.success("Aggiunta nuova quantità al monte ore per straordinari di %s",
person.getFullname());
handleOvertimeGroup(person.getGroups().get(0).id);
}

}

Expand Down
Loading

0 comments on commit b3a7885

Please sign in to comment.