Vacaciones #79
@ -121,7 +121,8 @@ public class DocumentsListView extends BaseView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String getEmployeeLabel(final Employee employee) {
|
private String getEmployeeLabel(final Employee employee) {
|
||||||
return employee.getFirstName().equals("TODOS") ? "TODOS" : employee.getFirstName() + " " + employee.getLastName();
|
return employee.getFirstName().equals("TODOS")
|
||||||
|
? "TODOS" : employee.getFirstName() + " " + employee.getLastName();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void navigateToEditDocumentView(final Document document) {
|
private void navigateToEditDocumentView(final Document document) {
|
||||||
|
@ -130,43 +130,47 @@ public class RequestEmployeeView extends Div implements HasUrlParameter<String>
|
|||||||
Employee employee = employeeService.getEmployee(employeeId);
|
Employee employee = employeeService.getEmployee(employeeId);
|
||||||
boolean isMale = employee.getGender() == Employee.Gender.MALE;
|
boolean isMale = employee.getGender() == Employee.Gender.MALE;
|
||||||
int currentYear = LocalDate.now().getYear();
|
int currentYear = LocalDate.now().getYear();
|
||||||
|
LocalDate currentDate = LocalDate.now();
|
||||||
|
|
||||||
List<Vacation> vacations = vacationService.findVacations();
|
List<Vacation> vacations = vacationService.findVacations();
|
||||||
|
|
||||||
double healthLicence = 2;
|
double healthLicence = getHealthLicence(employeeId);
|
||||||
List<TimeOffRequest> healthRequests = requestService
|
|
||||||
.findByEmployeeAndCategory(employeeId, TimeOffRequestType.PERMISOS_DE_SALUD);
|
|
||||||
if (healthRequests != null && !healthRequests.isEmpty()) {
|
|
||||||
healthLicence = healthRequests.getLast().getDaysBalance();
|
|
||||||
}
|
|
||||||
|
|
||||||
double totalFixedAndMovableHolidays = calculateHolidayDays(vacations);
|
double totalFixedAndMovableHolidays = calculateHolidayDays(vacations);
|
||||||
double totalPersonalDays = calculatePersonalDays(vacations, isMale);
|
double totalPersonalDays = calculatePersonalDays(vacations, isMale);
|
||||||
List<Double> vacationDays = calculateVacationDays(employee);
|
List<Double> vacationDays = calculateVacationDays(employee);
|
||||||
|
|
||||||
double utilizedVacationCurrentDays = vacationDays.get(1);
|
double totalVacationCurrentDays = calculateUtilizedVacationDays(
|
||||||
List<TimeOffRequest> vacationCurrentRequests = requestService
|
vacationDays.get(1),
|
||||||
.findByEmployeeAndCategory(employeeId, TimeOffRequestType.VACACION_GESTION_ACTUAL);
|
TimeOffRequestType.VACACION_GESTION_ACTUAL
|
||||||
if (vacationCurrentRequests != null && !vacationCurrentRequests.isEmpty()) {
|
);
|
||||||
utilizedVacationCurrentDays = vacationCurrentRequests.getLast().getDaysBalance();
|
double totalVacationPreviousDays = calculateUtilizedVacationDays(
|
||||||
}
|
vacationDays.get(0),
|
||||||
double totalVacationCurrentDays = vacationDays.get(1) - (vacationDays.get(1) - utilizedVacationCurrentDays);
|
TimeOffRequestType.VACACION_GESTION_ANTERIOR
|
||||||
|
);
|
||||||
double utilizedVacationPreviousDays = vacationDays.get(0);
|
|
||||||
List<TimeOffRequest> vacationPreviousRequests = requestService
|
|
||||||
.findByEmployeeAndCategory(employeeId, TimeOffRequestType.VACACION_GESTION_ANTERIOR);
|
|
||||||
if (vacationPreviousRequests != null && !vacationPreviousRequests.isEmpty()) {
|
|
||||||
utilizedVacationPreviousDays = vacationPreviousRequests.getLast().getDaysBalance();
|
|
||||||
}
|
|
||||||
double totalVacationPreviousDays = vacationDays.getFirst()
|
|
||||||
- (vacationDays.getFirst() - utilizedVacationPreviousDays);
|
|
||||||
|
|
||||||
double utilizedFixedAndMovableHolidays = calculateHolidayUtilizedDays(currentYear);
|
double utilizedFixedAndMovableHolidays = calculateHolidayUtilizedDays(currentYear);
|
||||||
double utilizedPersonalDays = calculatePersonalDaysUtilized(isMale, currentYear);
|
double utilizedPersonalDays = calculatePersonalDaysUtilized(isMale, currentYear);
|
||||||
|
|
||||||
double remainingHolidayDays = totalFixedAndMovableHolidays - utilizedFixedAndMovableHolidays;
|
double remainingHolidayDays = calculateRemainingHolidayDays(
|
||||||
double remainingPersonalDays = (totalPersonalDays - utilizedPersonalDays) + healthLicence;
|
totalFixedAndMovableHolidays,
|
||||||
double remainingVacationDays = totalVacationCurrentDays + totalVacationPreviousDays;
|
utilizedFixedAndMovableHolidays,
|
||||||
|
employee.getDateOfExit(),
|
||||||
|
currentDate
|
||||||
|
);
|
||||||
|
double remainingPersonalDays = calculateRemainingPersonalDays(
|
||||||
|
totalPersonalDays,
|
||||||
|
utilizedPersonalDays,
|
||||||
|
healthLicence,
|
||||||
|
employee.getDateOfExit(),
|
||||||
|
currentDate
|
||||||
|
);
|
||||||
|
double remainingVacationDays = calculateRemainingVacationDays(
|
||||||
|
totalVacationCurrentDays,
|
||||||
|
totalVacationPreviousDays,
|
||||||
|
employee.getDateOfExit(),
|
||||||
|
currentDate
|
||||||
|
);
|
||||||
|
|
||||||
double totalAvailableDays = remainingHolidayDays + remainingPersonalDays + remainingVacationDays;
|
double totalAvailableDays = remainingHolidayDays + remainingPersonalDays + remainingVacationDays;
|
||||||
|
|
||||||
@ -178,6 +182,51 @@ public class RequestEmployeeView extends Div implements HasUrlParameter<String>
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private double getHealthLicence(final UUID employeeId) {
|
||||||
|
List<TimeOffRequest> healthRequests = requestService
|
||||||
|
.findByEmployeeAndCategory(employeeId, TimeOffRequestType.PERMISOS_DE_SALUD);
|
||||||
|
return healthRequests != null && !healthRequests.isEmpty() ? healthRequests.getLast().getDaysBalance() : 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
private double calculateUtilizedVacationDays(final double vacationDays, final TimeOffRequestType requestType) {
|
||||||
|
List<TimeOffRequest> vacationRequests = requestService.findByEmployeeAndCategory(employeeId, requestType);
|
||||||
|
if (vacationRequests != null && !vacationRequests.isEmpty()) {
|
||||||
|
return vacationRequests.getLast().getDaysBalance();
|
||||||
|
}
|
||||||
|
return vacationDays;
|
||||||
|
}
|
||||||
|
|
||||||
|
private double calculateRemainingVacationDays(final double totalVacationCurrentDays,
|
||||||
|
final double totalVacationPreviousDays,
|
||||||
|
final LocalDate exitDate,
|
||||||
|
final LocalDate currentDate) {
|
||||||
|
if (exitDate == null || exitDate.isAfter(currentDate)) {
|
||||||
|
return totalVacationCurrentDays + totalVacationPreviousDays;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private double calculateRemainingHolidayDays(final double totalFixedAndMovableHolidays,
|
||||||
|
final double utilizedFixedAndMovableHolidays,
|
||||||
|
final LocalDate exitDate,
|
||||||
|
final LocalDate currentDate) {
|
||||||
|
if (exitDate == null || exitDate.isAfter(currentDate)) {
|
||||||
|
return totalFixedAndMovableHolidays - utilizedFixedAndMovableHolidays;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private double calculateRemainingPersonalDays(final double totalPersonalDays,
|
||||||
|
final double utilizedPersonalDays,
|
||||||
|
final double healthLicence,
|
||||||
|
final LocalDate exitDate,
|
||||||
|
final LocalDate currentDate) {
|
||||||
|
if (exitDate == null || exitDate.isAfter(currentDate)) {
|
||||||
|
return (totalPersonalDays - utilizedPersonalDays) + healthLicence;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
private double calculateHolidayDays(final List<Vacation> vacations) {
|
private double calculateHolidayDays(final List<Vacation> vacations) {
|
||||||
return vacations.stream()
|
return vacations.stream()
|
||||||
.filter(req -> req.getType() != Vacation.Type.OTHER)
|
.filter(req -> req.getType() != Vacation.Type.OTHER)
|
||||||
@ -413,13 +462,20 @@ public class RequestEmployeeView extends Div implements HasUrlParameter<String>
|
|||||||
employeeId = UUID.fromString(parameter);
|
employeeId = UUID.fromString(parameter);
|
||||||
Employee employee = employeeService.getEmployee(employeeId);
|
Employee employee = employeeService.getEmployee(employeeId);
|
||||||
requests = requestService.findRequestsByEmployeeId(employeeId);
|
requests = requestService.findRequestsByEmployeeId(employeeId);
|
||||||
setViewTitle(employee.getFirstName() + " " + employee.getLastName(), employee.getTeam().getName());
|
setViewTitle(
|
||||||
|
employee.getFirstName() + " " + employee.getLastName(),
|
||||||
|
employee.getTeam().getName(),
|
||||||
|
employee.getDateOfExit()
|
||||||
|
);
|
||||||
requestGrid.setItems(requests);
|
requestGrid.setItems(requests);
|
||||||
initializeView();
|
initializeView();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setViewTitle(final String employeeName, final String employeeTeam) {
|
private void setViewTitle(final String employeeName, final String employeeTeam, final LocalDate dateOfExit) {
|
||||||
addComponentAsFirst(new H3("Nombre del empleado: " + employeeName));
|
addComponentAsFirst(new H3("Nombre del empleado: " + employeeName));
|
||||||
addComponentAtIndex(1, new H3("Equipo: " + employeeTeam));
|
addComponentAtIndex(1, new H3("Equipo: " + employeeTeam));
|
||||||
|
if (dateOfExit != null) {
|
||||||
|
addComponentAtIndex(2, new H3("Descontado a cero en fecha " + dateOfExit + " por pago de finiquito."));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -191,6 +191,13 @@ public class RequestsListView extends BaseView {
|
|||||||
double totalAvailable = calculateTotalAvailable(vacations, employeeRequests, employee);
|
double totalAvailable = calculateTotalAvailable(vacations, employeeRequests, employee);
|
||||||
|
|
||||||
double generalTotal = totalAvailable + totalVacations - totalUtilized;
|
double generalTotal = totalAvailable + totalVacations - totalUtilized;
|
||||||
|
|
||||||
|
if (employee.getDateOfExit() != null
|
||||||
|
&& (employee.getDateOfExit().isBefore(LocalDate.now())
|
||||||
|
|| employee.getDateOfExit().isEqual(LocalDate.now()))) {
|
||||||
|
generalTotal = 0;
|
||||||
|
}
|
||||||
|
|
||||||
return String.valueOf(generalTotal);
|
return String.valueOf(generalTotal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user