From 8ab5016757f23e096e0b64b673e88fca0e55ea99 Mon Sep 17 00:00:00 2001 From: ricardo051199 Date: Sat, 19 Oct 2024 00:01:15 -0400 Subject: [PATCH 1/8] =?UTF-8?q?#55=20Perfil=20de=20Personal=20Administrati?= =?UTF-8?q?vo=20-=20A=C3=B1adir=20Vacaciones=20del=20Empleado=20(Crear=20b?= =?UTF-8?q?ase=20BD=20vacaciones)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../model/TimeOffRequestType.java | 27 +++++++++-- .../primefactorsolutions/model/Vacation.java | 31 ++++++++++++ .../repositories/VacationRepository.java | 11 +++++ .../service/VacationService.java | 18 +++++++ .../views/RequestRegisterView.java | 6 +-- src/main/resources/data.sql | 47 +++++++++++++++---- 6 files changed, 122 insertions(+), 18 deletions(-) create mode 100644 src/main/java/com/primefactorsolutions/model/Vacation.java create mode 100644 src/main/java/com/primefactorsolutions/repositories/VacationRepository.java create mode 100644 src/main/java/com/primefactorsolutions/service/VacationService.java diff --git a/src/main/java/com/primefactorsolutions/model/TimeOffRequestType.java b/src/main/java/com/primefactorsolutions/model/TimeOffRequestType.java index 8e25fee..32277b8 100644 --- a/src/main/java/com/primefactorsolutions/model/TimeOffRequestType.java +++ b/src/main/java/com/primefactorsolutions/model/TimeOffRequestType.java @@ -2,9 +2,28 @@ package com.primefactorsolutions.model; public enum TimeOffRequestType { ALL, - VACATION, - MATERNITY, + NEW_YEAR, + MONDAY_CARNIVAL, + TUESDAY_CARNIVAL, + GOOD_FRIDAY, + LABOR_DAY, + INDEPENDENCE_DAY, + CHRISTMAS, + PRURINATIONAL_STATE_DAY, + CORPUS_CHRISTI, + ANDEAN_NEW_YEAR, + DEPARTMENTAL_ANNIVERSARY, + ALL_SOULS_DAY, + BIRTHDAY, - FIXED_HOLIDAY, - OTHER + MATERNITY, + PATERNITY, + MARRIAGE, + FATHERS_DAY, + MOTHERS_DAY, + INTERNATIONAL_WOMENS_DAY, + NATIONAL_WOMENS_DAY, + HEALTH_PERMIT, + VACATION_CURRENT_MANAGEMENT, + VACATION_PREVIOUS_MANAGEMENT, } diff --git a/src/main/java/com/primefactorsolutions/model/Vacation.java b/src/main/java/com/primefactorsolutions/model/Vacation.java new file mode 100644 index 0000000..9f7de1c --- /dev/null +++ b/src/main/java/com/primefactorsolutions/model/Vacation.java @@ -0,0 +1,31 @@ +package com.primefactorsolutions.model; + +import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; + +import java.time.LocalDate; + +@Data +@Entity +@AllArgsConstructor +@NoArgsConstructor +@EqualsAndHashCode(callSuper = true) +public class Vacation extends BaseEntity { + @Enumerated(EnumType.STRING) + private TimeOffRequestType category; + private LocalDate vacationDate; + private Double duration; + private Double expiration; + @Enumerated(EnumType.STRING) + private Type type; + public enum Type { + FIXED, + MOVABLE, + OTHER + } +} diff --git a/src/main/java/com/primefactorsolutions/repositories/VacationRepository.java b/src/main/java/com/primefactorsolutions/repositories/VacationRepository.java new file mode 100644 index 0000000..0cb852f --- /dev/null +++ b/src/main/java/com/primefactorsolutions/repositories/VacationRepository.java @@ -0,0 +1,11 @@ +package com.primefactorsolutions.repositories; + +import com.primefactorsolutions.model.TimeOffRequestType; +import com.primefactorsolutions.model.Vacation; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.UUID; + +public interface VacationRepository extends JpaRepository { + Vacation findByCategory(TimeOffRequestType category); +} diff --git a/src/main/java/com/primefactorsolutions/service/VacationService.java b/src/main/java/com/primefactorsolutions/service/VacationService.java new file mode 100644 index 0000000..056b73c --- /dev/null +++ b/src/main/java/com/primefactorsolutions/service/VacationService.java @@ -0,0 +1,18 @@ +package com.primefactorsolutions.service; + +import com.primefactorsolutions.model.TimeOffRequestType; +import com.primefactorsolutions.model.Vacation; +import com.primefactorsolutions.repositories.VacationRepository; +import lombok.AllArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@AllArgsConstructor +public class VacationService { + private final VacationRepository vacationRepository; + + public Vacation findVacation(final TimeOffRequestType category) { + return vacationRepository.findByCategory(category); + } + +} diff --git a/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java b/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java index 3ff6798..0a5f32b 100644 --- a/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java +++ b/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java @@ -28,9 +28,9 @@ public class RequestRegisterView extends VerticalLayout { private final ComboBox employeeComboBox = new ComboBox<>("Employee"); private final ComboBox categoryComboBox = new ComboBox<>("Category"); + private final NumberField availableDaysField = new NumberField("Available Days"); 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"); @@ -82,10 +82,6 @@ public class RequestRegisterView extends VerticalLayout { .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); diff --git a/src/main/resources/data.sql b/src/main/resources/data.sql index 5aca318..82b4fbb 100644 --- a/src/main/resources/data.sql +++ b/src/main/resources/data.sql @@ -16,6 +16,35 @@ INSERT INTO team (id, version, name) VALUES ('c3a8a7b1-f2d9-48c0-86ea-f215c2e6b3 INSERT INTO team (id, version, name) VALUES ('8f6b61e7-efb2-4de7-b8ed-7438c9d8babe', 1, 'GHI'); +INSERT INTO vacation (id, version, category, vacation_date, duration, expiration, type) VALUES ('123e4567-e89b-12d3-a456-426614174000', 1, 'NEW_YEAR', '2024-01-01', 1, 0, 'FIXED'); +INSERT INTO vacation (id, version, category, vacation_date, duration, expiration, type) VALUES ('223e4567-e89b-12d3-a456-426614174001', 1, 'MONDAY_CARNIVAL', '2024-02-12', 1, 0, 'FIXED'); +INSERT INTO vacation (id, version, category, vacation_date, duration, expiration, type) VALUES ('323e4567-e89b-12d3-a456-426614174002', 1, 'TUESDAY_CARNIVAL', '2024-02-13', 1, 0, 'FIXED'); +INSERT INTO vacation (id, version, category, vacation_date, duration, expiration, type) VALUES ('423e4567-e89b-12d3-a456-426614174003', 1, 'GOOD_FRIDAY', '2024-03-29', 1, 0, 'FIXED'); +INSERT INTO vacation (id, version, category, vacation_date, duration, expiration, type) VALUES ('523e4567-e89b-12d3-a456-426614174004', 1, 'LABOR_DAY', '2024-05-01', 1, 0, 'FIXED'); +INSERT INTO vacation (id, version, category, vacation_date, duration, expiration, type) VALUES ('623e4567-e89b-12d3-a456-426614174005', 1, 'INDEPENDENCE_DAY', '2024-08-06', 1, 0, 'FIXED'); +INSERT INTO vacation (id, version, category, vacation_date, duration, expiration, type) VALUES ('723e4567-e89b-12d3-a456-426614174006', 1, 'CHRISTMAS', '2024-12-25', 1, 0, 'FIXED'); + + +INSERT INTO vacation (id, version, category, vacation_date, duration, expiration, type) VALUES ('823e4567-e89b-12d3-a456-426614174007', 1, 'PRURINATIONAL_STATE_DAY', '2024-01-21', 1, 30, 'MOVABLE'); +INSERT INTO vacation (id, version, category, vacation_date, duration, expiration, type) VALUES ('923e4567-e89b-12d3-a456-426614174008', 1, 'CORPUS_CHRISTI', '2024-05-30', 1, 30, 'MOVABLE'); +INSERT INTO vacation (id, version, category, vacation_date, duration, expiration, type) VALUES ('a23e4567-e89b-12d3-a456-426614174009', 1, 'ANDEAN_NEW_YEAR', '2024-06-21', 1, 30, 'MOVABLE'); +INSERT INTO vacation (id, version, category, vacation_date, duration, expiration, type) VALUES ('b23e4567-e89b-12d3-a456-42661417400a', 1, 'DEPARTMENTAL_ANNIVERSARY', '2024-09-14', 1, 30, 'MOVABLE'); +INSERT INTO vacation (id, version, category, vacation_date, duration, expiration, type) VALUES ('c23e4567-e89b-12d3-a456-42661417400b', 1, 'ALL_SOULS_DAY', '2024-11-02', 1, 30, 'MOVABLE'); + + +INSERT INTO vacation (id, version, category, duration, expiration, type) VALUES ('c23e4567-e89b-12d3-a456-42661417400c', 1, 'BIRTHDAY', 0.5, 365, 'OTHER'); +INSERT INTO vacation (id, version, category, duration, expiration, type) VALUES ('c23e4567-e89b-12d3-a456-42661417400d', 1, 'MATERNITY', 90, 90, 'OTHER'); +INSERT INTO vacation (id, version, category, duration, expiration, type) VALUES ('c23e4567-e89b-12d3-a456-42661417400e', 1, 'PATERNITY', 3, 3, 'OTHER'); +INSERT INTO vacation (id, version, category, duration, expiration, type) VALUES ('c23e4567-e89b-12d3-a456-42661417400f', 1, 'MARRIAGE', 3, 3, 'OTHER'); +INSERT INTO vacation (id, version, category, vacation_date, duration, expiration, type) VALUES ('c23e4567-e89b-12d3-a456-42661417401a', 1, 'FATHERS_DAY', '2024-03-19', 0.5, 30, 'OTHER'); +INSERT INTO vacation (id, version, category, vacation_date, duration, expiration, type) VALUES ('c23e4567-e89b-12d3-a456-42661417401b', 1, 'MOTHERS_DAY', '2024-05-27', 0.5, 30, 'OTHER'); +INSERT INTO vacation (id, version, category, vacation_date, duration, expiration, type) VALUES ('c23e4567-e89b-12d3-a456-42661417401c', 1, 'INTERNATIONAL_WOMENS_DAY', '2024-03-08', 0.5, 30, 'OTHER'); +INSERT INTO vacation (id, version, category, vacation_date, duration, expiration, type) VALUES ('c23e4567-e89b-12d3-a456-42661417401d', 1, 'NATIONAL_WOMENS_DAY', '2024-10-11', 0.5, 30, 'OTHER'); +INSERT INTO vacation (id, version, category, duration, type) VALUES ('c23e4567-e89b-12d3-a456-42661417401e', 1, 'HEALTH_PERMIT', 2, 'OTHER'); +INSERT INTO vacation (id, version, category, expiration, type) VALUES ('490e5fbe-895b-42f8-b914-95437f7b39c0', 1, 'VACATION_CURRENT_MANAGEMENT', 730, 'OTHER'); +INSERT INTO vacation (id, version, category, expiration, type) VALUES ('c23e4567-e89b-12d3-a456-4266141740ff', 1, 'VACATION_PREVIOUS_MANAGEMENT', 730, 'OTHER'); + + insert into employee (id, version, username, first_name, last_name, status, team_id) values ('5c6f11fe-c341-4be7-a9a6-bba0081ad7c6', 1, 'bob', 'Bob', 'Test', 'ACTIVE','b0e8f394-78c1-4d8a-9c57-dc6e8b36a5fa'); insert into employee (id, version, username, first_name, last_name, status, team_id) values ('cba3efb7-32bc-44be-9fdc-fc5e4f211254', 1, 'ben', 'Ben', 'Test', 'ACTIVE', '6d63bc15-3f8b-46f7-9cf1-7e9b0b9a2b28'); insert into employee (id, version, username, first_name, last_name, status, team_id) values ('e99b7af5-7d3a-4c0f-b8bc-e8d0388d8fc4', 1, 'jperez', 'Juan', 'Perez Condori', 'INACTIVE', 'c3a8a7b1-f2d9-48c0-86ea-f215c2e6b3a3'); @@ -37,32 +66,32 @@ insert into employee (id, version, username, first_name, last_name, status, team insert into time_off_request (id, version, employee_id, category, state, available_days, expiration, start_date, end_date, days_to_be_take, days_balance) -values ('9d6f12ba-e341-4e7a-b8a6-cab0982bd8c1', 1, '5c6f11fe-c341-4be7-a9a6-bba0081ad7c6', 'VACATION', 'TAKEN', 15, '2025-12-31', '2024-10-01', '2024-10-10', 5, 10); +values ('9d6f12ba-e341-4e7a-b8a6-cab0982bd8c1', 1, '5c6f11fe-c341-4be7-a9a6-bba0081ad7c6', 'PATERNITY', 'TAKEN', 15, '2025-12-31', '2024-10-01', '2024-10-10', 5, 10); insert into time_off_request (id, version, employee_id, category, state, available_days, expiration, start_date, end_date, days_to_be_take, days_balance) values ('2fa314bc-f547-4b12-a8b6-bb789feabc12', 1, '19b5a76e-d7b1-4b76-8b02-4d0748e85809', 'BIRTHDAY', 'APPROVED', 15, '2025-12-31', '2024-12-01', '2024-12-15', 7, 8); insert into time_off_request (id, version, employee_id, category, state, available_days, expiration, start_date, end_date, days_to_be_take, days_balance) -values ('d5f6341a-913d-4e7f-a0b2-cfe0786acd34', 1, 'cba3efb7-32bc-44be-9fdc-fc5e4f211254', 'FIXED_HOLIDAY', 'IN_USE', 20, '2025-11-30', '2024-11-10', '2024-11-20', 10, 10); +values ('d5f6341a-913d-4e7f-a0b2-cfe0786acd34', 1, 'cba3efb7-32bc-44be-9fdc-fc5e4f211254', 'HEALTH_PERMIT', 'IN_USE', 20, '2025-11-30', '2024-11-10', '2024-11-20', 10, 10); insert into time_off_request (id, version, employee_id, category, state, available_days, expiration, start_date, end_date, days_to_be_take, days_balance) values ('4f913b23-ff23-4527-bcd6-adfe01234567', 1, 'e99b7af5-7d3a-4c0f-b8bc-e8d0388d8fc4', 'MATERNITY', 'IN_USE', 18, '2025-06-30', '2024-07-01', '2024-07-15', 10, 8); insert into time_off_request (id, version, employee_id, category, state, available_days, expiration, start_date, end_date, days_to_be_take, days_balance) -values ('8c653f2a-f9a3-4d67-b3b6-12ad98fe0983', 1, 'f6ab3c6d-7078-45f6-9b22-4e37637bfec6', 'VACATION', 'REQUESTED', 10, '2025-10-31', '2024-09-15', '2024-09-20', 5, 5); +values ('8c653f2a-f9a3-4d67-b3b6-12ad98fe0983', 1, 'f6ab3c6d-7078-45f6-9b22-4e37637bfec6', 'LABOR_DAY', 'REQUESTED', 10, '2025-10-31', '2024-09-15', '2024-09-20', 5, 5); insert into time_off_request (id, version, employee_id, category, state, available_days, expiration, start_date, end_date, days_to_be_take, days_balance) -values ('fb9d9d75-b2ab-4ea4-b8b3-0a8f89e5c123', 1, '2e2293b1-3f9a-4f3d-abc8-32639b0a5e15', 'FIXED_HOLIDAY', 'IN_USE', 12, '2025-08-31', '2024-08-05', '2024-08-15', 6, 6); +values ('fb9d9d75-b2ab-4ea4-b8b3-0a8f89e5c123', 1, '2e2293b1-3f9a-4f3d-abc8-32639b0a5e15', 'INDEPENDENCE_DAY', 'IN_USE', 12, '2025-08-31', '2024-08-05', '2024-08-15', 6, 6); insert into time_off_request (id, version, employee_id, category, state, available_days, expiration, start_date, end_date, days_to_be_take, days_balance) values ('1c913a12-46e9-47b7-9e31-ab903fedc789', 1, '4b1c6c35-4627-4b35-b6e9-dc75c68b2c31', 'BIRTHDAY', 'APPROVED', 14, '2025-12-31', '2024-10-20', '2024-10-25', 5, 9); insert into time_off_request (id, version, employee_id, category, state, available_days, expiration, start_date, end_date, days_to_be_take, days_balance) values ('b1249d3a-cc34-4954-88d9-1e4f67fe2436', 1, 'afc5c741-f70a-4394-853b-39d51b118927', 'MATERNITY', 'APPROVED', 20, '2025-11-30', '2024-11-05', '2024-11-12', 7, 13); insert into time_off_request (id, version, employee_id, category, state, available_days, expiration, start_date, end_date, days_to_be_take, days_balance) -values ('6fdc47a8-127b-41c4-8d12-7fc12098ab12', 1, 'b2436b82-7b9f-4f0d-9463-f2c3173a45c3', 'VACATION', 'PENDING', 18, '2025-06-30', '2024-07-10', '2024-07-20', 8, 10); +values ('6fdc47a8-127b-41c4-8d12-7fc12098ab12', 1, 'b2436b82-7b9f-4f0d-9463-f2c3173a45c3', 'ALL_SOULS_DAY', 'PENDING', 18, '2025-06-30', '2024-07-10', '2024-07-20', 8, 10); insert into time_off_request (id, version, employee_id, category, state, available_days, expiration, start_date, end_date, days_to_be_take, days_balance) -values ('12ec8b74-983d-4a17-b67e-134f45ae904c', 1, '5c1a7b82-832d-4f24-8377-54b77b91b6a8', 'FIXED_HOLIDAY', 'PENDING', 15, '2025-12-31', '2024-09-01', '2024-09-05', 4, 11); +values ('12ec8b74-983d-4a17-b67e-134f45ae904c', 1, '5c1a7b82-832d-4f24-8377-54b77b91b6a8', 'NEW_YEAR', 'PENDING', 15, '2025-12-31', '2024-09-01', '2024-09-05', 4, 11); insert into time_off_request (id, version, employee_id, category, state, available_days, expiration, start_date, end_date, days_to_be_take, days_balance) -values ('89bc4b2a-943f-487c-a9f3-bacf78145e67', 1, 'cba3efb7-32bc-44be-9fdc-fc5e4f211254', 'VACATION', 'APPROVED', 20, '2025-11-30', '2024-10-25', '2024-11-05', 9, 11); +values ('89bc4b2a-943f-487c-a9f3-bacf78145e67', 1, 'cba3efb7-32bc-44be-9fdc-fc5e4f211254', 'MONDAY_CARNIVAL', 'APPROVED', 20, '2025-11-30', '2024-10-25', '2024-11-05', 9, 11); insert into time_off_request (id, version, employee_id, category, state, available_days, expiration, start_date, end_date, days_to_be_take, days_balance) values ('37adfc2a-7463-4b2d-a7c1-fae04567cdef', 1, 'e99b7af5-7d3a-4c0f-b8bc-e8d0388d8fc4', 'BIRTHDAY', 'REQUESTED', 18, '2025-06-30', '2024-06-01', '2024-06-10', 6, 12); insert into time_off_request (id, version, employee_id, category, state, available_days, expiration, start_date, end_date, days_to_be_take, days_balance) values ('2bc138ea-12db-4b89-a0b4-78e045e34b4e', 1, 'f6ab3c6d-7078-45f6-9b22-4e37637bfec6', 'MATERNITY', 'REQUESTED', 10, '2025-10-31', '2024-10-01', '2024-10-10', 3, 7); insert into time_off_request (id, version, employee_id, category, state, available_days, expiration, start_date, end_date, days_to_be_take, days_balance) -values ('14de1a56-6893-4e12-90f3-4faec457f002', 1, 'cd80e1d0-9a08-44a6-bd63-2c63eaa003d4', 'FIXED_HOLIDAY', 'PENDING', 22, '2025-08-31', '2024-07-15', '2024-07-25', 8, 14); +values ('14de1a56-6893-4e12-90f3-4faec457f002', 1, 'cd80e1d0-9a08-44a6-bd63-2c63eaa003d4', 'HEALTH_PERMIT', 'PENDING', 22, '2025-08-31', '2024-07-15', '2024-07-25', 8, 14); insert into time_off_request (id, version, employee_id, category, state, available_days, expiration, start_date, end_date, days_to_be_take, days_balance) -values ('fb08a6c9-cd17-42e8-b9e2-734ec834cae2', 1, '4b1c6c35-4627-4b35-b6e9-dc75c68b2c31', 'VACATION', 'PENDING', 16, '2025-12-31', '2024-09-30', '2024-10-05', 4, 12); +values ('fb08a6c9-cd17-42e8-b9e2-734ec834cae2', 1, '4b1c6c35-4627-4b35-b6e9-dc75c68b2c31', 'HEALTH_PERMIT', 'PENDING', 16, '2025-12-31', '2024-09-30', '2024-10-05', 4, 12); -- 2.34.1 From a37b93591fdee953dc00268abab5f79158ec9d4d Mon Sep 17 00:00:00 2001 From: ricardo051199 Date: Sun, 20 Oct 2024 15:05:05 -0400 Subject: [PATCH 2/8] =?UTF-8?q?#55=20Perfil=20de=20Personal=20Administrati?= =?UTF-8?q?vo=20-=20A=C3=B1adir=20Vacaciones=20del=20Empleado=20(Guardar?= =?UTF-8?q?=20solicitud)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/VacationService.java | 2 +- .../views/RequestRegisterView.java | 83 ++++++++++++++++++- src/main/resources/data.sql | 14 ++-- 3 files changed, 87 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/primefactorsolutions/service/VacationService.java b/src/main/java/com/primefactorsolutions/service/VacationService.java index 056b73c..15db4b0 100644 --- a/src/main/java/com/primefactorsolutions/service/VacationService.java +++ b/src/main/java/com/primefactorsolutions/service/VacationService.java @@ -11,7 +11,7 @@ import org.springframework.stereotype.Service; public class VacationService { private final VacationRepository vacationRepository; - public Vacation findVacation(final TimeOffRequestType category) { + public Vacation findVacationByCategory(final TimeOffRequestType category) { return vacationRepository.findByCategory(category); } diff --git a/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java b/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java index 0a5f32b..3dcd9c3 100644 --- a/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java +++ b/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java @@ -3,6 +3,7 @@ package com.primefactorsolutions.views; import com.primefactorsolutions.model.*; import com.primefactorsolutions.service.EmployeeService; import com.primefactorsolutions.service.TimeOffRequestService; +import com.primefactorsolutions.service.VacationService; import com.vaadin.flow.component.button.Button; import com.vaadin.flow.component.combobox.ComboBox; import com.vaadin.flow.component.datepicker.DatePicker; @@ -17,6 +18,7 @@ import com.vaadin.flow.spring.annotation.SpringComponent; import jakarta.annotation.security.PermitAll; import org.springframework.context.annotation.Scope; +import java.time.LocalDate; import java.util.List; @SpringComponent @@ -36,15 +38,20 @@ public class RequestRegisterView extends VerticalLayout { private final TimeOffRequestService requestService; private final EmployeeService employeeService; + private final VacationService vacationService; + private final Binder binder; + private LocalDate endDate; private Button saveButton; private Button closeButton; public RequestRegisterView(final TimeOffRequestService requestService, - final EmployeeService employeeService) { + final EmployeeService employeeService, + final VacationService vacationService) { this.requestService = requestService; this.employeeService = employeeService; + this.vacationService = vacationService; this.binder = new Binder<>(TimeOffRequest.class); configureFormFields(); @@ -58,6 +65,71 @@ public class RequestRegisterView extends VerticalLayout { employeeComboBox.setItems(employees); employeeComboBox.setItemLabelGenerator(emp -> emp.getFirstName() + " " + emp.getLastName()); categoryComboBox.setItems(TimeOffRequestType.values()); + categoryComboBox.addValueChangeListener(event -> updateAvailableDays(event.getValue())); + startDatePicker.addValueChangeListener(event -> updateDatePickerMinValues()); + endDatePicker.addValueChangeListener(event -> calculateDays()); + availableDaysField.setReadOnly(true); + daysToBeTakenField.setReadOnly(true); + balanceDaysField.setReadOnly(true); + } + + private void updateAvailableDays(TimeOffRequestType selectedCategory) { + if (selectedCategory != null) { + Vacation vacation = vacationService.findVacationByCategory(selectedCategory); + if (vacation != null) { + availableDaysField.setValue(vacation.getDuration()); + setDatePickerLimits(vacation); + } + } + } + + private void setDatePickerLimits(Vacation vacation) { + LocalDate startDate = vacation.getVacationDate(); + endDate = startDate.plusDays(vacation.getExpiration().intValue() - 1); + startDatePicker.setMin(startDate); + startDatePicker.setMax(endDate); + endDatePicker.setMin(startDate); + endDatePicker.setMax(endDate); + + startDatePicker.clear(); + endDatePicker.clear(); + getUI().ifPresent(ui -> ui.access(() -> { + startDatePicker.setInitialPosition(startDate); + })); + } + + private void updateDatePickerMinValues() { + LocalDate startDate = startDatePicker.getValue(); + if (startDate != null) { + endDatePicker.setMin(startDate); + endDatePicker.setInitialPosition(startDate); + calculateDays(); + } + } + + private void calculateDays() { + LocalDate startDate = startDatePicker.getValue(); + LocalDate endDate = endDatePicker.getValue(); + Double availableDays = availableDaysField.getValue(); + + if (startDate != null && endDate != null) { + if (startDate.isAfter(endDate)) { + endDatePicker.clear(); + return; + } + + long daysToBeTaken = java.time.temporal.ChronoUnit.DAYS.between(startDate, endDate) + 1; + daysToBeTakenField.setValue((double) daysToBeTaken); + + double balanceDays = availableDays - daysToBeTaken; + if (balanceDays < 0) { + endDatePicker.clear(); + daysToBeTakenField.clear(); + balanceDaysField.clear(); + } else { + balanceDaysField.setValue(balanceDays); + } + } } private void configureButtons() { @@ -74,6 +146,9 @@ public class RequestRegisterView extends VerticalLayout { .asRequired("Category is required") .bind(TimeOffRequest::getCategory, TimeOffRequest::setCategory); + binder.forField(availableDaysField) + .bind(TimeOffRequest::getAvailableDays, TimeOffRequest::setAvailableDays); + binder.forField(startDatePicker) .asRequired("Start date is required") .bind(TimeOffRequest::getStartDate, TimeOffRequest::setStartDate); @@ -83,11 +158,9 @@ public class RequestRegisterView extends VerticalLayout { .bind(TimeOffRequest::getEndDate, TimeOffRequest::setEndDate); 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()); @@ -98,9 +171,9 @@ public class RequestRegisterView extends VerticalLayout { new H3("Add Vacation Request"), employeeComboBox, categoryComboBox, + availableDaysField, startDatePicker, endDatePicker, - availableDaysField, daysToBeTakenField, balanceDaysField, new HorizontalLayout(saveButton, closeButton) @@ -110,6 +183,8 @@ public class RequestRegisterView extends VerticalLayout { private void saveRequest() { if (binder.validate().isOk()) { TimeOffRequest request = binder.getBean(); + request.setExpiration(endDate); + request.setState(TimeOffRequestStatus.REQUESTED); requestService.saveTimeOffRequest(request); Notification.show("Request saved successfully."); closeForm(); diff --git a/src/main/resources/data.sql b/src/main/resources/data.sql index 82b4fbb..39efdb3 100644 --- a/src/main/resources/data.sql +++ b/src/main/resources/data.sql @@ -16,13 +16,13 @@ INSERT INTO team (id, version, name) VALUES ('c3a8a7b1-f2d9-48c0-86ea-f215c2e6b3 INSERT INTO team (id, version, name) VALUES ('8f6b61e7-efb2-4de7-b8ed-7438c9d8babe', 1, 'GHI'); -INSERT INTO vacation (id, version, category, vacation_date, duration, expiration, type) VALUES ('123e4567-e89b-12d3-a456-426614174000', 1, 'NEW_YEAR', '2024-01-01', 1, 0, 'FIXED'); -INSERT INTO vacation (id, version, category, vacation_date, duration, expiration, type) VALUES ('223e4567-e89b-12d3-a456-426614174001', 1, 'MONDAY_CARNIVAL', '2024-02-12', 1, 0, 'FIXED'); -INSERT INTO vacation (id, version, category, vacation_date, duration, expiration, type) VALUES ('323e4567-e89b-12d3-a456-426614174002', 1, 'TUESDAY_CARNIVAL', '2024-02-13', 1, 0, 'FIXED'); -INSERT INTO vacation (id, version, category, vacation_date, duration, expiration, type) VALUES ('423e4567-e89b-12d3-a456-426614174003', 1, 'GOOD_FRIDAY', '2024-03-29', 1, 0, 'FIXED'); -INSERT INTO vacation (id, version, category, vacation_date, duration, expiration, type) VALUES ('523e4567-e89b-12d3-a456-426614174004', 1, 'LABOR_DAY', '2024-05-01', 1, 0, 'FIXED'); -INSERT INTO vacation (id, version, category, vacation_date, duration, expiration, type) VALUES ('623e4567-e89b-12d3-a456-426614174005', 1, 'INDEPENDENCE_DAY', '2024-08-06', 1, 0, 'FIXED'); -INSERT INTO vacation (id, version, category, vacation_date, duration, expiration, type) VALUES ('723e4567-e89b-12d3-a456-426614174006', 1, 'CHRISTMAS', '2024-12-25', 1, 0, 'FIXED'); +INSERT INTO vacation (id, version, category, vacation_date, duration, expiration, type) VALUES ('123e4567-e89b-12d3-a456-426614174000', 1, 'NEW_YEAR', '2024-01-01', 1, 1, 'FIXED'); +INSERT INTO vacation (id, version, category, vacation_date, duration, expiration, type) VALUES ('223e4567-e89b-12d3-a456-426614174001', 1, 'MONDAY_CARNIVAL', '2024-02-12', 1, 1, 'FIXED'); +INSERT INTO vacation (id, version, category, vacation_date, duration, expiration, type) VALUES ('323e4567-e89b-12d3-a456-426614174002', 1, 'TUESDAY_CARNIVAL', '2024-02-13', 1, 1, 'FIXED'); +INSERT INTO vacation (id, version, category, vacation_date, duration, expiration, type) VALUES ('423e4567-e89b-12d3-a456-426614174003', 1, 'GOOD_FRIDAY', '2024-03-29', 1, 1, 'FIXED'); +INSERT INTO vacation (id, version, category, vacation_date, duration, expiration, type) VALUES ('523e4567-e89b-12d3-a456-426614174004', 1, 'LABOR_DAY', '2024-05-01', 1, 1, 'FIXED'); +INSERT INTO vacation (id, version, category, vacation_date, duration, expiration, type) VALUES ('623e4567-e89b-12d3-a456-426614174005', 1, 'INDEPENDENCE_DAY', '2024-08-06', 1, 1, 'FIXED'); +INSERT INTO vacation (id, version, category, vacation_date, duration, expiration, type) VALUES ('723e4567-e89b-12d3-a456-426614174006', 1, 'CHRISTMAS', '2024-12-25', 1, 1, 'FIXED'); INSERT INTO vacation (id, version, category, vacation_date, duration, expiration, type) VALUES ('823e4567-e89b-12d3-a456-426614174007', 1, 'PRURINATIONAL_STATE_DAY', '2024-01-21', 1, 30, 'MOVABLE'); -- 2.34.1 From 2c30bed91f1caa4cae8c8e870ecd2750cd973462 Mon Sep 17 00:00:00 2001 From: ricardo051199 Date: Sun, 20 Oct 2024 15:11:24 -0400 Subject: [PATCH 3/8] =?UTF-8?q?#55=20Perfil=20de=20Personal=20Administrati?= =?UTF-8?q?vo=20-=20A=C3=B1adir=20Vacaciones=20del=20Empleado=20(Actualiza?= =?UTF-8?q?r=20automaticamente=20fechas)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../primefactorsolutions/views/RequestRegisterView.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java b/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java index 3dcd9c3..1ff9172 100644 --- a/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java +++ b/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java @@ -91,11 +91,8 @@ public class RequestRegisterView extends VerticalLayout { endDatePicker.setMin(startDate); endDatePicker.setMax(endDate); - startDatePicker.clear(); - endDatePicker.clear(); - getUI().ifPresent(ui -> ui.access(() -> { - startDatePicker.setInitialPosition(startDate); - })); + startDatePicker.setValue(startDate); + endDatePicker.setValue(startDate.plusDays(vacation.getDuration().intValue() - 1)); } private void updateDatePickerMinValues() { -- 2.34.1 From 2582c5e903c946f7d9a88cc9ac159e1e4971757f Mon Sep 17 00:00:00 2001 From: ricardo051199 Date: Sun, 20 Oct 2024 15:16:34 -0400 Subject: [PATCH 4/8] =?UTF-8?q?#55=20Perfil=20de=20Personal=20Administrati?= =?UTF-8?q?vo=20-=20A=C3=B1adir=20Vacaciones=20del=20Empleado=20(Para=20se?= =?UTF-8?q?leccionar=20categoria=20requerir=20empleado)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/primefactorsolutions/views/RequestRegisterView.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java b/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java index 1ff9172..ba57022 100644 --- a/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java +++ b/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java @@ -64,8 +64,14 @@ public class RequestRegisterView extends VerticalLayout { List employees = employeeService.findAllEmployees(); employeeComboBox.setItems(employees); employeeComboBox.setItemLabelGenerator(emp -> emp.getFirstName() + " " + emp.getLastName()); + categoryComboBox.setEnabled(false); categoryComboBox.setItems(TimeOffRequestType.values()); categoryComboBox.addValueChangeListener(event -> updateAvailableDays(event.getValue())); + employeeComboBox.addValueChangeListener(event -> { + if (event.getValue() != null) { + categoryComboBox.setEnabled(true); + } + }); startDatePicker.addValueChangeListener(event -> updateDatePickerMinValues()); endDatePicker.addValueChangeListener(event -> calculateDays()); availableDaysField.setReadOnly(true); -- 2.34.1 From 1c18cd566ff3718370f49ad5df9fad24adec3e0f Mon Sep 17 00:00:00 2001 From: ricardo051199 Date: Sun, 20 Oct 2024 18:24:40 -0400 Subject: [PATCH 5/8] =?UTF-8?q?#55=20Perfil=20de=20Personal=20Administrati?= =?UTF-8?q?vo=20-=20A=C3=B1adir=20Vacaciones=20del=20Empleado=20(Excluir?= =?UTF-8?q?=20las=20categorias=20que=20cuenten=20con=20un=20registro)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../views/RequestRegisterView.java | 15 ++++++++++++++- src/main/resources/data.sql | 2 +- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java b/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java index ba57022..6b5e4ac 100644 --- a/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java +++ b/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java @@ -19,6 +19,7 @@ import jakarta.annotation.security.PermitAll; import org.springframework.context.annotation.Scope; import java.time.LocalDate; +import java.util.Arrays; import java.util.List; @SpringComponent @@ -65,11 +66,12 @@ public class RequestRegisterView extends VerticalLayout { employeeComboBox.setItems(employees); employeeComboBox.setItemLabelGenerator(emp -> emp.getFirstName() + " " + emp.getLastName()); categoryComboBox.setEnabled(false); - categoryComboBox.setItems(TimeOffRequestType.values()); categoryComboBox.addValueChangeListener(event -> updateAvailableDays(event.getValue())); employeeComboBox.addValueChangeListener(event -> { + Employee selectedEmployee = event.getValue(); if (event.getValue() != null) { categoryComboBox.setEnabled(true); + filterCategories(selectedEmployee); } }); startDatePicker.addValueChangeListener(event -> updateDatePickerMinValues()); @@ -79,6 +81,17 @@ public class RequestRegisterView extends VerticalLayout { balanceDaysField.setReadOnly(true); } + private void filterCategories(Employee employee) { + List employeeRequests = requestService.findRequestsByEmployeeId(employee.getId()); + List requestedCategories = employeeRequests.stream() + .map(TimeOffRequest::getCategory) + .toList(); + List availableCategories = Arrays.stream(TimeOffRequestType.values()) + .filter(category -> !requestedCategories.contains(category)) + .toList(); + categoryComboBox.setItems(availableCategories); + } + private void updateAvailableDays(TimeOffRequestType selectedCategory) { if (selectedCategory != null) { Vacation vacation = vacationService.findVacationByCategory(selectedCategory); diff --git a/src/main/resources/data.sql b/src/main/resources/data.sql index 39efdb3..cd96f24 100644 --- a/src/main/resources/data.sql +++ b/src/main/resources/data.sql @@ -25,7 +25,7 @@ INSERT INTO vacation (id, version, category, vacation_date, duration, expiration INSERT INTO vacation (id, version, category, vacation_date, duration, expiration, type) VALUES ('723e4567-e89b-12d3-a456-426614174006', 1, 'CHRISTMAS', '2024-12-25', 1, 1, 'FIXED'); -INSERT INTO vacation (id, version, category, vacation_date, duration, expiration, type) VALUES ('823e4567-e89b-12d3-a456-426614174007', 1, 'PRURINATIONAL_STATE_DAY', '2024-01-21', 1, 30, 'MOVABLE'); +INSERT INTO vacation (id, version, category, vacation_date, duration, expiration, type) VALUES ('823e4567-e89b-12d3-a456-426614174007', 1, 'PRURINATIONAL_STATE_DAY', '2024-01-21', 3, 30, 'MOVABLE'); INSERT INTO vacation (id, version, category, vacation_date, duration, expiration, type) VALUES ('923e4567-e89b-12d3-a456-426614174008', 1, 'CORPUS_CHRISTI', '2024-05-30', 1, 30, 'MOVABLE'); INSERT INTO vacation (id, version, category, vacation_date, duration, expiration, type) VALUES ('a23e4567-e89b-12d3-a456-426614174009', 1, 'ANDEAN_NEW_YEAR', '2024-06-21', 1, 30, 'MOVABLE'); INSERT INTO vacation (id, version, category, vacation_date, duration, expiration, type) VALUES ('b23e4567-e89b-12d3-a456-42661417400a', 1, 'DEPARTMENTAL_ANNIVERSARY', '2024-09-14', 1, 30, 'MOVABLE'); -- 2.34.1 From 0858566e8ee997125372d31bbf7ab0096dc4c72e Mon Sep 17 00:00:00 2001 From: ricardo051199 Date: Sun, 20 Oct 2024 22:49:47 -0400 Subject: [PATCH 6/8] =?UTF-8?q?#55=20Perfil=20de=20Personal=20Administrati?= =?UTF-8?q?vo=20-=20A=C3=B1adir=20Vacaciones=20del=20Empleado=20(Inactivar?= =?UTF-8?q?=20categoria=20por=20genero)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../views/RequestRegisterView.java | 33 ++++++++++++++--- src/main/resources/data.sql | 36 +++++++++---------- 2 files changed, 47 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java b/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java index 6b5e4ac..cd73249 100644 --- a/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java +++ b/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java @@ -42,6 +42,7 @@ public class RequestRegisterView extends VerticalLayout { private final VacationService vacationService; private final Binder binder; + private Vacation vacation; private LocalDate endDate; private Button saveButton; @@ -68,6 +69,7 @@ public class RequestRegisterView extends VerticalLayout { categoryComboBox.setEnabled(false); categoryComboBox.addValueChangeListener(event -> updateAvailableDays(event.getValue())); employeeComboBox.addValueChangeListener(event -> { + clearForm(); Employee selectedEmployee = event.getValue(); if (event.getValue() != null) { categoryComboBox.setEnabled(true); @@ -88,13 +90,24 @@ public class RequestRegisterView extends VerticalLayout { .toList(); List availableCategories = Arrays.stream(TimeOffRequestType.values()) .filter(category -> !requestedCategories.contains(category)) + .filter(category -> { + if (employee.getGender() == Employee.Gender.MALE) { + return category != TimeOffRequestType.MATERNITY && + category != TimeOffRequestType.MOTHERS_DAY && + category != TimeOffRequestType.INTERNATIONAL_WOMENS_DAY && + category != TimeOffRequestType.NATIONAL_WOMENS_DAY; + } else { + return category != TimeOffRequestType.FATHERS_DAY && + category != TimeOffRequestType.PATERNITY; + } + }) .toList(); categoryComboBox.setItems(availableCategories); } private void updateAvailableDays(TimeOffRequestType selectedCategory) { if (selectedCategory != null) { - Vacation vacation = vacationService.findVacationByCategory(selectedCategory); + vacation = vacationService.findVacationByCategory(selectedCategory); if (vacation != null) { availableDaysField.setValue(vacation.getDuration()); setDatePickerLimits(vacation); @@ -118,7 +131,7 @@ public class RequestRegisterView extends VerticalLayout { LocalDate startDate = startDatePicker.getValue(); if (startDate != null) { endDatePicker.setMin(startDate); - endDatePicker.setInitialPosition(startDate); + endDatePicker.setValue(startDate.plusDays(vacation.getDuration().intValue() - 1)); calculateDays(); } } @@ -134,8 +147,11 @@ public class RequestRegisterView extends VerticalLayout { return; } - long daysToBeTaken = java.time.temporal.ChronoUnit.DAYS.between(startDate, endDate) + 1; - daysToBeTakenField.setValue((double) daysToBeTaken); + double daysToBeTaken = java.time.temporal.ChronoUnit.DAYS.between(startDate, endDate) + 1; + if (daysToBeTaken == 1 && vacation.getDuration() == 0.5) { + daysToBeTaken = 0.5; + } + daysToBeTakenField.setValue(daysToBeTaken); double balanceDays = availableDays - daysToBeTaken; if (balanceDays < 0) { @@ -212,4 +228,13 @@ public class RequestRegisterView extends VerticalLayout { private void closeForm() { getUI().ifPresent(ui -> ui.navigate(RequestsListView.class)); } + + private void clearForm() { + categoryComboBox.clear(); + availableDaysField.clear(); + startDatePicker.clear(); + endDatePicker.clear(); + daysToBeTakenField.clear(); + balanceDaysField.clear(); + } } diff --git a/src/main/resources/data.sql b/src/main/resources/data.sql index cd96f24..d6890d2 100644 --- a/src/main/resources/data.sql +++ b/src/main/resources/data.sql @@ -45,24 +45,24 @@ INSERT INTO vacation (id, version, category, expiration, type) VALUES ('490e5fbe INSERT INTO vacation (id, version, category, expiration, type) VALUES ('c23e4567-e89b-12d3-a456-4266141740ff', 1, 'VACATION_PREVIOUS_MANAGEMENT', 730, 'OTHER'); -insert into employee (id, version, username, first_name, last_name, status, team_id) values ('5c6f11fe-c341-4be7-a9a6-bba0081ad7c6', 1, 'bob', 'Bob', 'Test', 'ACTIVE','b0e8f394-78c1-4d8a-9c57-dc6e8b36a5fa'); -insert into employee (id, version, username, first_name, last_name, status, team_id) values ('cba3efb7-32bc-44be-9fdc-fc5e4f211254', 1, 'ben', 'Ben', 'Test', 'ACTIVE', '6d63bc15-3f8b-46f7-9cf1-7e9b0b9a2b28'); -insert into employee (id, version, username, first_name, last_name, status, team_id) values ('e99b7af5-7d3a-4c0f-b8bc-e8d0388d8fc4', 1, 'jperez', 'Juan', 'Perez Condori', 'INACTIVE', 'c3a8a7b1-f2d9-48c0-86ea-f215c2e6b3a3'); -insert into employee (id, version, username, first_name, last_name, status, team_id) values ('f6ab3c6d-7078-45f6-9b22-4e37637bfec6', 1, 'agarcia', 'Ana', 'Garcia Rojas', 'ACTIVE', '8f6b61e7-efb2-4de7-b8ed-7438c9d8babe'); -insert into employee (id, version, username, first_name, last_name, status, team_id) values ('2e2293b1-3f9a-4f3d-abc8-32639b0a5e15', 1, 'clopez', 'Carlos', 'Lopez Mendoza', 'INACTIVE', 'b0e8f394-78c1-4d8a-9c57-dc6e8b36a5fa'); -insert into employee (id, version, username, first_name, last_name, status, team_id) values ('4b1c6c35-4627-4b35-b6e9-dc75c68b2c31', 1, 'mfernandez', 'Maria', 'Fernandez Villca', 'ACTIVE', '6d63bc15-3f8b-46f7-9cf1-7e9b0b9a2b28'); -insert into employee (id, version, username, first_name, last_name, status, team_id) values ('afc5c741-f70a-4394-853b-39d51b118927', 1, 'lgutierrez', 'Luis', 'Gutierrez Mamani', 'ACTIVE', 'c3a8a7b1-f2d9-48c0-86ea-f215c2e6b3a3'); -insert into employee (id, version, username, first_name, last_name, status, team_id) values ('b2436b82-7b9f-4f0d-9463-f2c3173a45c3', 1, 'lmartinez', 'Laura', 'Martinez Paredes', 'INACTIVE', '8f6b61e7-efb2-4de7-b8ed-7438c9d8babe'); -insert into employee (id, version, username, first_name, last_name, status, team_id) values ('6e6a8a4e-9f6b-44eb-8c69-40acfdc86756', 1, 'rsantos', 'Roberto', 'Santos Escobar', 'ACTIVE','b0e8f394-78c1-4d8a-9c57-dc6e8b36a5fa'); -insert into employee (id, version, username, first_name, last_name, status, team_id) values ('36b0d1c6-bdc0-4d98-94bb-08b9bce3f0d5', 1, 'vmorales', 'Valeria', 'Morales Ochoa', 'INACTIVE', '6d63bc15-3f8b-46f7-9cf1-7e9b0b9a2b28'); -insert into employee (id, version, username, first_name, last_name, status, team_id) values ('5a1c6d80-58b3-43e3-a5a5-24b4a2d1d54a', 1, 'jramirez', 'Jorge', 'Ramirez Tapia', 'ACTIVE', 'c3a8a7b1-f2d9-48c0-86ea-f215c2e6b3a3'); -insert into employee (id, version, username, first_name, last_name, status, team_id) values ('9d6a5b2e-6d0b-4b89-8d6a-d3f3d1bfc047', 1, 'storres', 'Sandra', 'Torres Huanca', 'ACTIVE', '8f6b61e7-efb2-4de7-b8ed-7438c9d8babe'); -insert into employee (id, version, username, first_name, last_name, status, team_id) values ('f8b3e0c0-0d5a-4e5c-bf9d-207b9b5e8279', 1, 'fquispe', 'Felipe', 'Quispe Huanca', 'INACTIVE','b0e8f394-78c1-4d8a-9c57-dc6e8b36a5fa'); -insert into employee (id, version, username, first_name, last_name, status, team_id) values ('cd80e1d0-9a08-44a6-bd63-2c63eaa003d4', 1, 'grivas', 'Gabriela', 'Rivas Arana', 'ACTIVE', '6d63bc15-3f8b-46f7-9cf1-7e9b0b9a2b28'); -insert into employee (id, version, username, first_name, last_name, status, team_id) values ('62d3c1b7-815e-4e96-8d7e-f8c4236bca55', 1, 'oflores', 'Oscar', 'Flores Quiroga', 'INACTIVE', 'c3a8a7b1-f2d9-48c0-86ea-f215c2e6b3a3'); -insert into employee (id, version, username, first_name, last_name, status, team_id) values ('f20b7c5a-5a67-44f0-9ec1-4c1b8e80de05', 1, 'mvargas', 'Marta', 'Vargas Soria', 'ACTIVE', '8f6b61e7-efb2-4de7-b8ed-7438c9d8babe'); -insert into employee (id, version, username, first_name, last_name, status, team_id) values ('19b5a76e-d7b1-4b76-8b02-4d0748e85809', 1, 'aespinoza', 'Andres', 'Espinoza Chura', 'INACTIVE','b0e8f394-78c1-4d8a-9c57-dc6e8b36a5fa'); -insert into employee (id, version, username, first_name, last_name, status, team_id) values ('5c1a7b82-832d-4f24-8377-54b77b91b6a8', 1, 'cvillanueva', 'Carla', 'Villanueva Arce', 'ACTIVE', '6d63bc15-3f8b-46f7-9cf1-7e9b0b9a2b28'); +insert into employee (id, version, username, first_name, last_name, status, team_id, gender) values ('5c6f11fe-c341-4be7-a9a6-bba0081ad7c6', 1, 'bob', 'Bob', 'Test', 'ACTIVE','b0e8f394-78c1-4d8a-9c57-dc6e8b36a5fa', 'MALE'); +insert into employee (id, version, username, first_name, last_name, status, team_id, gender) values ('cba3efb7-32bc-44be-9fdc-fc5e4f211254', 1, 'ben', 'Ben', 'Test', 'ACTIVE', '6d63bc15-3f8b-46f7-9cf1-7e9b0b9a2b28', 'MALE'); +insert into employee (id, version, username, first_name, last_name, status, team_id, gender) values ('e99b7af5-7d3a-4c0f-b8bc-e8d0388d8fc4', 1, 'jperez', 'Juan', 'Perez Condori', 'INACTIVE', 'c3a8a7b1-f2d9-48c0-86ea-f215c2e6b3a3', 'MALE'); +insert into employee (id, version, username, first_name, last_name, status, team_id, gender) values ('f6ab3c6d-7078-45f6-9b22-4e37637bfec6', 1, 'agarcia', 'Ana', 'Garcia Rojas', 'ACTIVE', '8f6b61e7-efb2-4de7-b8ed-7438c9d8babe', 'FEMALE'); +insert into employee (id, version, username, first_name, last_name, status, team_id, gender) values ('2e2293b1-3f9a-4f3d-abc8-32639b0a5e15', 1, 'clopez', 'Carlos', 'Lopez Mendoza', 'INACTIVE', 'b0e8f394-78c1-4d8a-9c57-dc6e8b36a5fa', 'MALE'); +insert into employee (id, version, username, first_name, last_name, status, team_id, gender) values ('4b1c6c35-4627-4b35-b6e9-dc75c68b2c31', 1, 'mfernandez', 'Maria', 'Fernandez Villca', 'ACTIVE', '6d63bc15-3f8b-46f7-9cf1-7e9b0b9a2b28', 'FEMALE'); +insert into employee (id, version, username, first_name, last_name, status, team_id, gender) values ('afc5c741-f70a-4394-853b-39d51b118927', 1, 'lgutierrez', 'Luis', 'Gutierrez Mamani', 'ACTIVE', 'c3a8a7b1-f2d9-48c0-86ea-f215c2e6b3a3', 'MALE'); +insert into employee (id, version, username, first_name, last_name, status, team_id, gender) values ('b2436b82-7b9f-4f0d-9463-f2c3173a45c3', 1, 'lmartinez', 'Laura', 'Martinez Paredes', 'INACTIVE', '8f6b61e7-efb2-4de7-b8ed-7438c9d8babe', 'FEMALE'); +insert into employee (id, version, username, first_name, last_name, status, team_id, gender) values ('6e6a8a4e-9f6b-44eb-8c69-40acfdc86756', 1, 'rsantos', 'Roberto', 'Santos Escobar', 'ACTIVE','b0e8f394-78c1-4d8a-9c57-dc6e8b36a5fa', 'MALE'); +insert into employee (id, version, username, first_name, last_name, status, team_id, gender) values ('36b0d1c6-bdc0-4d98-94bb-08b9bce3f0d5', 1, 'vmorales', 'Valeria', 'Morales Ochoa', 'INACTIVE', '6d63bc15-3f8b-46f7-9cf1-7e9b0b9a2b28', 'FEMALE'); +insert into employee (id, version, username, first_name, last_name, status, team_id, gender) values ('5a1c6d80-58b3-43e3-a5a5-24b4a2d1d54a', 1, 'jramirez', 'Jorge', 'Ramirez Tapia', 'ACTIVE', 'c3a8a7b1-f2d9-48c0-86ea-f215c2e6b3a3', 'MALE'); +insert into employee (id, version, username, first_name, last_name, status, team_id, gender) values ('9d6a5b2e-6d0b-4b89-8d6a-d3f3d1bfc047', 1, 'storres', 'Sandra', 'Torres Huanca', 'ACTIVE', '8f6b61e7-efb2-4de7-b8ed-7438c9d8babe', 'FEMALE'); +insert into employee (id, version, username, first_name, last_name, status, team_id, gender) values ('f8b3e0c0-0d5a-4e5c-bf9d-207b9b5e8279', 1, 'fquispe', 'Felipe', 'Quispe Huanca', 'INACTIVE','b0e8f394-78c1-4d8a-9c57-dc6e8b36a5fa', 'MALE'); +insert into employee (id, version, username, first_name, last_name, status, team_id, gender) values ('cd80e1d0-9a08-44a6-bd63-2c63eaa003d4', 1, 'grivas', 'Gabriela', 'Rivas Arana', 'ACTIVE', '6d63bc15-3f8b-46f7-9cf1-7e9b0b9a2b28', 'FEMALE'); +insert into employee (id, version, username, first_name, last_name, status, team_id, gender) values ('62d3c1b7-815e-4e96-8d7e-f8c4236bca55', 1, 'oflores', 'Oscar', 'Flores Quiroga', 'INACTIVE', 'c3a8a7b1-f2d9-48c0-86ea-f215c2e6b3a3', 'MALE'); +insert into employee (id, version, username, first_name, last_name, status, team_id, gender) values ('f20b7c5a-5a67-44f0-9ec1-4c1b8e80de05', 1, 'mvargas', 'Marta', 'Vargas Soria', 'ACTIVE', '8f6b61e7-efb2-4de7-b8ed-7438c9d8babe', 'FEMALE'); +insert into employee (id, version, username, first_name, last_name, status, team_id, gender) values ('19b5a76e-d7b1-4b76-8b02-4d0748e85809', 1, 'aespinoza', 'Andres', 'Espinoza Chura', 'INACTIVE','b0e8f394-78c1-4d8a-9c57-dc6e8b36a5fa', 'MALE'); +insert into employee (id, version, username, first_name, last_name, status, team_id, gender) values ('5c1a7b82-832d-4f24-8377-54b77b91b6a8', 1, 'cvillanueva', 'Carla', 'Villanueva Arce', 'ACTIVE', '6d63bc15-3f8b-46f7-9cf1-7e9b0b9a2b28', 'FEMALE'); insert into time_off_request (id, version, employee_id, category, state, available_days, expiration, start_date, end_date, days_to_be_take, days_balance) -- 2.34.1 From 69c61e093e5d76415514a06e4eb1f675bd55a366 Mon Sep 17 00:00:00 2001 From: ricardo051199 Date: Mon, 21 Oct 2024 12:14:26 -0400 Subject: [PATCH 7/8] =?UTF-8?q?#55=20Perfil=20de=20Personal=20Administrati?= =?UTF-8?q?vo=20-=20A=C3=B1adir=20Vacaciones=20del=20Empleado=20(Configuar?= =?UTF-8?q?a=20fecha=20manual)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../views/RequestRegisterView.java | 31 ++++++++++++++----- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java b/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java index cd73249..4fc4122 100644 --- a/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java +++ b/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java @@ -67,7 +67,10 @@ public class RequestRegisterView extends VerticalLayout { employeeComboBox.setItems(employees); employeeComboBox.setItemLabelGenerator(emp -> emp.getFirstName() + " " + emp.getLastName()); categoryComboBox.setEnabled(false); - categoryComboBox.addValueChangeListener(event -> updateAvailableDays(event.getValue())); + categoryComboBox.addValueChangeListener(event -> { + clearForm(); + updateAvailableDays(event.getValue()); + }); employeeComboBox.addValueChangeListener(event -> { clearForm(); Employee selectedEmployee = event.getValue(); @@ -116,22 +119,37 @@ public class RequestRegisterView extends VerticalLayout { } private void setDatePickerLimits(Vacation vacation) { - LocalDate startDate = vacation.getVacationDate(); - endDate = startDate.plusDays(vacation.getExpiration().intValue() - 1); + LocalDate startDate; + if (vacation.getVacationDate() != null) { + startDate = vacation.getVacationDate(); + endDate = startDate.plusDays(vacation.getExpiration().intValue() - 1); + startDatePicker.setValue(startDate); + endDatePicker.setValue(startDate.plusDays(vacation.getDuration().intValue() - 1)); + + } else { + startDate = LocalDate.now(); + endDate = null; + } startDatePicker.setMin(startDate); startDatePicker.setMax(endDate); endDatePicker.setMin(startDate); endDatePicker.setMax(endDate); - startDatePicker.setValue(startDate); - endDatePicker.setValue(startDate.plusDays(vacation.getDuration().intValue() - 1)); } private void updateDatePickerMinValues() { LocalDate startDate = startDatePicker.getValue(); + if (vacation.getVacationDate() == null) { + endDate = startDate.plusDays(vacation.getExpiration().intValue() - 1); + } if (startDate != null) { endDatePicker.setMin(startDate); - endDatePicker.setValue(startDate.plusDays(vacation.getDuration().intValue() - 1)); + endDatePicker.setMax(startDate.plusDays(vacation.getExpiration().intValue() - 1)); + if (vacation.getDuration() == 0.5) { + endDatePicker.setValue(startDate.plusDays(0)); + } else { + endDatePicker.setValue(startDate.plusDays(vacation.getDuration().intValue() - 1)); + } calculateDays(); } } @@ -230,7 +248,6 @@ public class RequestRegisterView extends VerticalLayout { } private void clearForm() { - categoryComboBox.clear(); availableDaysField.clear(); startDatePicker.clear(); endDatePicker.clear(); -- 2.34.1 From a5e166351a7e2f8469de68235f18bd5590510773 Mon Sep 17 00:00:00 2001 From: ricardo051199 Date: Mon, 21 Oct 2024 12:39:28 -0400 Subject: [PATCH 8/8] =?UTF-8?q?#55=20Perfil=20de=20Personal=20Administrati?= =?UTF-8?q?vo=20-=20A=C3=B1adir=20Vacaciones=20del=20Empleado=20(Refactori?= =?UTF-8?q?zacion=20configuracion=20form)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../views/RequestRegisterView.java | 119 +++++++++--------- 1 file changed, 59 insertions(+), 60 deletions(-) diff --git a/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java b/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java index 4fc4122..c4e0fd1 100644 --- a/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java +++ b/src/main/java/com/primefactorsolutions/views/RequestRegisterView.java @@ -63,22 +63,11 @@ public class RequestRegisterView extends VerticalLayout { } private void configureFormFields() { - List employees = employeeService.findAllEmployees(); - employeeComboBox.setItems(employees); + employeeComboBox.setItems(employeeService.findAllEmployees()); employeeComboBox.setItemLabelGenerator(emp -> emp.getFirstName() + " " + emp.getLastName()); + employeeComboBox.addValueChangeListener(event -> handleEmployeeSelection(event.getValue())); categoryComboBox.setEnabled(false); - categoryComboBox.addValueChangeListener(event -> { - clearForm(); - updateAvailableDays(event.getValue()); - }); - employeeComboBox.addValueChangeListener(event -> { - clearForm(); - Employee selectedEmployee = event.getValue(); - if (event.getValue() != null) { - categoryComboBox.setEnabled(true); - filterCategories(selectedEmployee); - } - }); + categoryComboBox.addValueChangeListener(event -> handleCategorySelection(event.getValue())); startDatePicker.addValueChangeListener(event -> updateDatePickerMinValues()); endDatePicker.addValueChangeListener(event -> calculateDays()); availableDaysField.setReadOnly(true); @@ -86,7 +75,44 @@ public class RequestRegisterView extends VerticalLayout { balanceDaysField.setReadOnly(true); } - private void filterCategories(Employee employee) { + 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(availableDaysField) + .bind(TimeOffRequest::getAvailableDays, TimeOffRequest::setAvailableDays); + + 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(daysToBeTakenField) + .bind(TimeOffRequest::getDaysToBeTake, TimeOffRequest::setDaysToBeTake); + + binder.forField(balanceDaysField) + .bind(TimeOffRequest::getDaysBalance, TimeOffRequest::setDaysBalance); + + binder.setBean(new TimeOffRequest()); + } + + private void handleEmployeeSelection(final Employee selectedEmployee) { + clearForm(); + if (selectedEmployee != null) { + categoryComboBox.setEnabled(true); + filterCategories(selectedEmployee); + } + } + + private void filterCategories(final Employee employee) { List employeeRequests = requestService.findRequestsByEmployeeId(employee.getId()); List requestedCategories = employeeRequests.stream() .map(TimeOffRequest::getCategory) @@ -95,37 +121,39 @@ public class RequestRegisterView extends VerticalLayout { .filter(category -> !requestedCategories.contains(category)) .filter(category -> { if (employee.getGender() == Employee.Gender.MALE) { - return category != TimeOffRequestType.MATERNITY && - category != TimeOffRequestType.MOTHERS_DAY && - category != TimeOffRequestType.INTERNATIONAL_WOMENS_DAY && - category != TimeOffRequestType.NATIONAL_WOMENS_DAY; + return category != TimeOffRequestType.MATERNITY + && category != TimeOffRequestType.MOTHERS_DAY + && category != TimeOffRequestType.INTERNATIONAL_WOMENS_DAY + && category != TimeOffRequestType.NATIONAL_WOMENS_DAY; } else { - return category != TimeOffRequestType.FATHERS_DAY && - category != TimeOffRequestType.PATERNITY; + return category != TimeOffRequestType.FATHERS_DAY + && category != TimeOffRequestType.PATERNITY; } }) .toList(); categoryComboBox.setItems(availableCategories); } - private void updateAvailableDays(TimeOffRequestType selectedCategory) { + private void handleCategorySelection(final TimeOffRequestType selectedCategory) { + clearForm(); if (selectedCategory != null) { - vacation = vacationService.findVacationByCategory(selectedCategory); - if (vacation != null) { - availableDaysField.setValue(vacation.getDuration()); - setDatePickerLimits(vacation); - } + updateAvailableDays(selectedCategory); } } - private void setDatePickerLimits(Vacation vacation) { + private void updateAvailableDays(final TimeOffRequestType selectedCategory) { + vacation = vacationService.findVacationByCategory(selectedCategory); + if (vacation != null) { + availableDaysField.setValue(vacation.getDuration()); + setDatePickerLimits(vacation); + } + } + + private void setDatePickerLimits(final Vacation vacation) { LocalDate startDate; if (vacation.getVacationDate() != null) { startDate = vacation.getVacationDate(); endDate = startDate.plusDays(vacation.getExpiration().intValue() - 1); - startDatePicker.setValue(startDate); - endDatePicker.setValue(startDate.plusDays(vacation.getDuration().intValue() - 1)); - } else { startDate = LocalDate.now(); endDate = null; @@ -187,35 +215,6 @@ public class RequestRegisterView extends VerticalLayout { 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(availableDaysField) - .bind(TimeOffRequest::getAvailableDays, TimeOffRequest::setAvailableDays); - - 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(daysToBeTakenField) - .bind(TimeOffRequest::getDaysToBeTake, TimeOffRequest::setDaysToBeTake); - - binder.forField(balanceDaysField) - .bind(TimeOffRequest::getDaysBalance, TimeOffRequest::setDaysBalance); - - binder.setBean(new TimeOffRequest()); - } - private void setupFormLayout() { add( new H3("Add Vacation Request"), -- 2.34.1