Skip to content

feat: alert on low remaining contract days - #200

Open
yoandiny wants to merge 29 commits into
hei-teacher:preprodfrom
Bradon614:low-remaining-days-alert
Open

feat: alert on low remaining contract days#200
yoandiny wants to merge 29 commits into
hei-teacher:preprodfrom
Bradon614:low-remaining-days-alert

Conversation

@yoandiny

Copy link
Copy Markdown

Summary

Add contract expiry alert system, display remaining contract days warning, and improve daily check-in UX.

Changes

Contract alert

- Check remaining contract days for each worker based on their active contract
- Show visual warning on the work and care calendar when remaining contract days drop below a configurable threshold
- Send automatic alert email to accountants when a contract is about to expire

Daily check-in UX

- Automatically pre-fill the current date in the daily execution submission field

yoandiny and others added 15 commits July 25, 2026 14:53
…ookup (#55)

Provide a dedicated query and service method so banner, remaining-days, and daily-execution guards can share one definition of a worker's active contract.
)

Compute remaining contract days from the active contract and worked days so banner and alert flows can share one source of truth.
* feat(event): add LowRemainingDaysAlertRequested event model carrying workerCode and remainingDays

* feat(service): add LowRemainingDaysAlertRequestedService to send async alert email to accountants when a worker has few days remaining on their contract

* chore: format code
* fix: auto-initialize spring session jdbc schema on startup

* feat: add contract and remaining days attributes to calendar controller

* feat: display contract and remaining days state on calendar

* feat: add findActiveContractByWorker for per-worker active contract lookup (#55)

Provide a dedicated query and service method so banner, remaining-days, and daily-execution guards can share one definition of a worker's active contract.

* feat: add getRemainingDaysOnActiveContractOrZero on ContractService (#56)

Compute remaining contract days from the active contract and worked days so banner and alert flows can share one source of truth.

* fix: drop LowRemainingDaysAlertService from calendar until it lands on base

Keep remaining-days UI attributes via ContractService; the alert service is not on low-remaining-days-alert yet.

---------

Co-authored-by: yoandiny <63061998+yoandiny@users.noreply.github.com>
Co-authored-by: yoandiny <yoandiny14@gmail.com>
- Create LowRemainingDaysAlertService with threshold check + event trigger + toast message
- Integrate into DailyExecutionController after daily execution save
- Fix locale bug in ContractService.executedDays (use Locale.US)
- Add LOW_REMAINING_DAYS_THRESHOLD env var to test config
- Add integration tests: below threshold, above threshold, no contract
Delete the temporary worker and contracts after each LowRemainingDaysAlertServiceIT run so WorkerServiceIT keeps a stable year-2026 dataset.
* feat: default date to today on daily-execution + unit tests on active contract/remaining days

* feat: default date to today on daily-execution + unit tests on active contract/remaining days

* test: add integration test for ContractService using TestContainers
* fix: reject punch-in when contract is inactive

* fix(test) : add active contract fixture to IT tests

* fix(test): add active contract fixture to CalendarServiceIT

* chore: format code

* fix(test): use fixed past dates for contract fixtures to avoid polluting year-based queries
* fix: restore calendar toast/DaysFormatter and treat zero days as no usable contract

Add missing template assets that caused 500s, and show the inactive-contract banner instead of a J-0 warning when remaining days are exhausted.

* fix: reject pointage with Loza error when worker has no usable contract

Throw instead of toast-redirect so ErrorHandler shows Loza Oops when there is no active contract or remaining days are exhausted.

* format code
Remove spring.session.jdbc.initialize-schema=always introduced in #59 so the file matches its upstream state again.
…#67)

List the env vars required for accountant emails and the low remaining days alert threshold for local runs.
Comment thread src/main/java/school/hei/asa/endpoint/rest/controller/CalendarController.java Outdated
Comment thread src/main/java/school/hei/asa/service/LowRemainingDaysAlertService.java Outdated
Comment thread src/main/java/school/hei/asa/endpoint/rest/controller/CalendarController.java Outdated
yoandiny added 2 commits July 28, 2026 12:05
* refactor: simplify low remaining alert wiring

Reduce review noise by removing duplicate alert-message construction and small helper indirections without touching upstream-owned tests.

* fix: remove unused import in alert requested service

Align the review-cleanup branch with CI formatting by dropping the unused InternetAddress import.
* refactor: simplify low remaining alert wiring

Reduce review noise by removing duplicate alert-message construction and small helper indirections without touching upstream-owned tests.

* fix: remove unused import in alert requested service

Align the review-cleanup branch with CI formatting by dropping the unused InternetAddress import.

* fix: align pointage and calendar flow with review feedback

Keep the low-days warning on redirect via flash attributes, add a repository guard for missing active contracts, and remove the calendar-side low-days warning rendering.
@yoandiny
yoandiny requested a review from SalomiaZK July 28, 2026 09:35
@yoandiny
yoandiny force-pushed the low-remaining-days-alert branch 2 times, most recently from b11ac8b to 757b63e Compare July 28, 2026 15:42
yoandiny and others added 3 commits July 28, 2026 19:37
Move alert message display off POST flash attributes onto the calendar Model, and keep email sending on pointage only.
* test: move alert IT fixtures to Flyway migration

Replace runtime worker/contract saves in LowRemainingDaysAlertServiceIT with stable V101_4 test data.

* format code

* test: keep alert fixtures out of WorkerServiceIT year 2026

Use 2027 entrance dates so low-remaining alert contracts are not returned by findByYearBetween(2026, 2027).
* refactor: replace long with double in remaining days handling

* fix: format the project
@yoandiny
yoandiny requested a review from SalomiaZK July 28, 2026 17:43
yoandiny added 4 commits July 28, 2026 21:34
* refactor: rename checkRemainingDays alert method to verify

Align naming with review feedback by renaming checkRemainingDaysAndBuildAlertMessage to verifyRemainingDaysAndBuildAlertMessage.

* style: apply google-java-format on alert service IT
Move save and low-remaining email trigger behind a single service method called from the controller.
yoandiny added 4 commits July 28, 2026 23:00
* Show low remaining days warning banner on daily-execution GET.

* Mirror calendar contract banners on daily-execution GET.
* Unify contract warning into one banner with conditional color.

* Format DailyExecutionController for google-java-format.

* Drop hasUsableContract; set banner color from message in the template.
Comment thread src/test/java/school/hei/asa/service/ContractServiceIT.java
Comment thread src/test/java/school/hei/asa/service/ContractServiceIT.java
Comment thread src/test/java/school/hei/asa/service/ContractServiceIT.java
Comment thread src/test/java/school/hei/asa/service/ContractServiceTest.java
Comment thread src/test/java/school/hei/asa/service/ContractServiceTest.java
Comment thread src/test/java/school/hei/asa/service/ContractServiceTest.java
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants