From 34940ff794c410efb4701a6a2407bcf5bff2d014 Mon Sep 17 00:00:00 2001 From: ricardo051199 Date: Wed, 16 Oct 2024 21:01:18 -0400 Subject: [PATCH 1/2] Lista de Vacaciones - Calcular totales de vacaciones --- .../views/RequestEmployeeView.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java b/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java index 8af34ea..95c9592 100644 --- a/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java +++ b/src/main/java/com/primefactorsolutions/views/RequestEmployeeView.java @@ -20,6 +20,7 @@ import com.vaadin.flow.spring.annotation.SpringComponent; import jakarta.annotation.security.PermitAll; import org.springframework.context.annotation.Scope; +import java.time.Year; import java.util.Collections; import java.util.List; import java.util.UUID; @@ -44,7 +45,6 @@ public class RequestEmployeeView extends Div implements HasUrlParameter public RequestEmployeeView(final TimeOffRequestService requestService, final EmployeeService employeeService) { this.requestService = requestService; this.employeeService = employeeService; - initializeView(); } private void initializeView() { @@ -97,9 +97,17 @@ public class RequestEmployeeView extends Div implements HasUrlParameter } private VerticalLayout createSummaryLayout() { - int totalVacations = 15; - int totalTimeOff = 2; - int totalAvailableDays = totalVacations + totalTimeOff; + int currentYear = Year.now().getValue(); + String yearCategory = "YEAR_" + currentYear; + double totalVacations = requests.stream() + .filter(req -> req.getCategory().name().equals(yearCategory)) + .mapToDouble(TimeOffRequest::getAvailableDays) + .sum(); + double totalTimeOff = requests.stream() + .filter(req -> !req.getCategory().name().startsWith("YEAR")) + .mapToDouble(TimeOffRequest::getDaysBalance) + .sum(); + double totalAvailableDays = totalVacations + totalTimeOff; return new VerticalLayout( new Span("TOTAL HOLIDAYS: " + totalVacations), new Span("TOTAL TIME OFF: " + totalTimeOff), @@ -176,6 +184,7 @@ public class RequestEmployeeView extends Div implements HasUrlParameter requests = requestService.findRequestsByEmployeeId(employeeId); setViewTitle(employee.getFirstName() + " " + employee.getLastName(), employee.getTeam().getName()); requestGrid.setItems(requests); + initializeView(); } private void setViewTitle(final String employeeName, final String employeeTeam) { -- 2.34.1 From 85dad4900ca30b448d4df3c1f72b9ae3258f3fea Mon Sep 17 00:00:00 2001 From: ricardo051199 Date: Fri, 18 Oct 2024 13:33:47 -0400 Subject: [PATCH 2/2] =?UTF-8?q?#55=20Perfil=20de=20Personal=20Administrati?= =?UTF-8?q?vo=20-=20A=C3=B1adir=20Vacaciones=20del=20Empleado?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../views/MainLayout.java | 2 + .../views/RequestRegisterView.java | 128 ++++++++++++++++++ 2 files changed, 130 insertions(+) create mode 100644 src/main/java/com/primefactorsolutions/views/RequestRegisterView.java diff --git a/src/main/java/com/primefactorsolutions/views/MainLayout.java b/src/main/java/com/primefactorsolutions/views/MainLayout.java index e64ad07..b5602f5 100644 --- a/src/main/java/com/primefactorsolutions/views/MainLayout.java +++ b/src/main/java/com/primefactorsolutions/views/MainLayout.java @@ -144,6 +144,8 @@ public class MainLayout extends AppLayout { LineAwesomeIcon.PLANE_DEPARTURE_SOLID.create()); timeOff.addItem(new SideNavItem("Vacations", RequestsListView.class, LineAwesomeIcon.SUN.create())); + timeOff.addItem(new SideNavItem("Add Vacation", RequestRegisterView.class, + LineAwesomeIcon.SUN.create())); SideNavItem timesheet = new SideNavItem("My Timesheet", TimesheetView.class, LineAwesomeIcon.HOURGLASS_START_SOLID.create()); timesheet.addItem(new SideNavItem("Hours Worked", HoursWorkedView.class, diff --git a/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java b/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java new file mode 100644 index 0000000..3ff6798 --- /dev/null +++ b/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java @@ -0,0 +1,128 @@ +package com.primefactorsolutions.views; + +import com.primefactorsolutions.model.*; +import com.primefactorsolutions.service.EmployeeService; +import com.primefactorsolutions.service.TimeOffRequestService; +import com.vaadin.flow.component.button.Button; +import com.vaadin.flow.component.combobox.ComboBox; +import com.vaadin.flow.component.datepicker.DatePicker; +import com.vaadin.flow.component.html.H3; +import com.vaadin.flow.component.notification.Notification; +import com.vaadin.flow.component.orderedlayout.HorizontalLayout; +import com.vaadin.flow.component.orderedlayout.VerticalLayout; +import com.vaadin.flow.component.textfield.NumberField; +import com.vaadin.flow.data.binder.Binder; +import com.vaadin.flow.router.*; +import com.vaadin.flow.spring.annotation.SpringComponent; +import jakarta.annotation.security.PermitAll; +import org.springframework.context.annotation.Scope; + +import java.util.List; + +@SpringComponent +@PermitAll +@Scope("prototype") +@PageTitle("Request") +@Route(value = "/requests/new", layout = MainLayout.class) +public class RequestRegisterView extends VerticalLayout { + + private final ComboBox employeeComboBox = new ComboBox<>("Employee"); + private final ComboBox categoryComboBox = new ComboBox<>("Category"); + private final DatePicker startDatePicker = new DatePicker("Start Date"); + private final DatePicker endDatePicker = new DatePicker("End Date"); + private final NumberField availableDaysField = new NumberField("Available Days"); + private final NumberField daysToBeTakenField = new NumberField("Days To Be Taken"); + private final NumberField balanceDaysField = new NumberField("Balance Days"); + + private final TimeOffRequestService requestService; + private final EmployeeService employeeService; + private final Binder binder; + + private Button saveButton; + private Button closeButton; + + public RequestRegisterView(final TimeOffRequestService requestService, + final EmployeeService employeeService) { + this.requestService = requestService; + this.employeeService = employeeService; + this.binder = new Binder<>(TimeOffRequest.class); + + configureFormFields(); + configureButtons(); + configureBinder(); + setupFormLayout(); + } + + private void configureFormFields() { + List employees = employeeService.findAllEmployees(); + employeeComboBox.setItems(employees); + employeeComboBox.setItemLabelGenerator(emp -> emp.getFirstName() + " " + emp.getLastName()); + categoryComboBox.setItems(TimeOffRequestType.values()); + } + + private void configureButtons() { + saveButton = new Button("Save", event -> saveRequest()); + closeButton = new Button("Close", event -> closeForm()); + } + + private void configureBinder() { + binder.forField(employeeComboBox) + .asRequired("Employee is required") + .bind(TimeOffRequest::getEmployee, TimeOffRequest::setEmployee); + + binder.forField(categoryComboBox) + .asRequired("Category is required") + .bind(TimeOffRequest::getCategory, TimeOffRequest::setCategory); + + binder.forField(startDatePicker) + .asRequired("Start date is required") + .bind(TimeOffRequest::getStartDate, TimeOffRequest::setStartDate); + + binder.forField(endDatePicker) + .asRequired("End date is required") + .bind(TimeOffRequest::getEndDate, TimeOffRequest::setEndDate); + + binder.forField(availableDaysField) + .asRequired("Available days is required") + .bind(TimeOffRequest::getAvailableDays, TimeOffRequest::setAvailableDays); + + binder.forField(daysToBeTakenField) + .asRequired("Days to be taken is required") + .bind(TimeOffRequest::getDaysToBeTake, TimeOffRequest::setDaysToBeTake); + + binder.forField(balanceDaysField) + .asRequired("Balance days is required") + .bind(TimeOffRequest::getDaysBalance, TimeOffRequest::setDaysBalance); + + binder.setBean(new TimeOffRequest()); + } + + private void setupFormLayout() { + add( + new H3("Add Vacation Request"), + employeeComboBox, + categoryComboBox, + startDatePicker, + endDatePicker, + availableDaysField, + daysToBeTakenField, + balanceDaysField, + new HorizontalLayout(saveButton, closeButton) + ); + } + + private void saveRequest() { + if (binder.validate().isOk()) { + TimeOffRequest request = binder.getBean(); + requestService.saveTimeOffRequest(request); + Notification.show("Request saved successfully."); + closeForm(); + } else { + Notification.show("Please fill all required fields correctly."); + } + } + + private void closeForm() { + getUI().ifPresent(ui -> ui.navigate(RequestsListView.class)); + } +} -- 2.34.1