Skip to content

Refactor workday service logic#40

Merged
jeyongsong merged 4 commits intomainfrom
refactor-workday-service
Mar 17, 2026
Merged

Refactor workday service logic#40
jeyongsong merged 4 commits intomainfrom
refactor-workday-service

Conversation

@jeyongsong
Copy link
Member

This pull request refactors the earnings calculation logic in the WorkdayService by introducing a new MemberEarningsService and consolidating date and schedule resolution helpers. The changes remove legacy calculator dependencies, unify schedule interpretation rules, and clarify the separation between display logic and settlement logic for daily earnings. The overall result is a cleaner, more maintainable codebase with improved modularity for payroll and workday calculations.

Earnings Calculation Refactor

  • Introduced MemberEarningsService as a dedicated service for member-level payroll and earnings calculations, replacing direct usage of EarningsCalculator and SalaryCalculator in WorkdayService. This new service centralizes monthly salary, daily earnings, and work minute calculations, delegating computation to CompensationCalculator and managing which payroll data to use. (src/main/kotlin/com/moa/service/MemberEarningsService.kt)
  • Replaced legacy calculator fields in WorkdayService with a single dependency on MemberEarningsService, updating all monthly and daily earnings logic to use the new service. (src/main/kotlin/com/moa/service/WorkdayService.kt) [1] [2] [3]

Schedule and Policy Resolution Helpers

  • Added helper methods to unify schedule resolution, monthly date range calculation, and policy lookup, reducing code duplication and ensuring consistent interpretation of saved schedules and policies across all endpoints. (src/main/kotlin/com/moa/service/WorkdayService.kt) [1] [2] [3] [4] [5] [6] [7] [8]

Daily Earnings and Display Logic Separation

  • Clarified the distinction between daily pay for display and earnings for settlement by introducing resolveDisplayedDailyPay and resolveCompletedWorkForSettlement helpers, ensuring that UI and accounting logic use the correct calculation for each context. (src/main/kotlin/com/moa/service/WorkdayService.kt) [1] [2]

Vacation Time Handling

  • Refactored vacation schedule time resolution into a dedicated helper (resolveVacationTimes), simplifying and centralizing the logic for determining which times to use when saving vacation days. (src/main/kotlin/com/moa/service/WorkdayService.kt)

Cleanup and Removal of Legacy Logic

  • Removed obsolete methods and logic, such as resolveClockOutForEarnings, now handled by the new helpers and service, further simplifying the code and improving maintainability. (src/main/kotlin/com/moa/service/WorkdayService.kt)

Copilot AI review requested due to automatic review settings March 17, 2026 18:38
@github-actions
Copy link

Test Results

52 tests   52 ✅  0s ⏱️
 7 suites   0 💤
 7 files     0 ❌

Results for commit 2446af4.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors earnings/workday calculation responsibilities by introducing MemberEarningsService (member-level payroll orchestration) and consolidating schedule/date/policy resolution helpers in WorkdayService, while replacing legacy calculator/service dependencies.

Changes:

  • Introduced MemberEarningsService to centralize payroll version lookup and daily/monthly earnings/minutes computation, delegating pure math to CompensationCalculator.
  • Refactored WorkdayService to use unified month range + schedule resolution helpers and to separate displayed daily pay vs settlement aggregation logic.
  • Removed legacy EarningsCalculator and replaced/renamed SalaryCalculator with CompensationCalculator, updating/adding tests accordingly.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/main/kotlin/com/moa/service/MemberEarningsService.kt New orchestrator service for payroll version selection + earnings/minutes calculations.
src/main/kotlin/com/moa/service/WorkdayService.kt Replaces legacy calculators with MemberEarningsService and adds schedule/month/policy helper methods + display/settlement separation.
src/main/kotlin/com/moa/service/calculator/CompensationCalculator.kt Renamed/refined pure calculation utility (daily rate, minutes, earnings, workdays in period).
src/main/kotlin/com/moa/service/calculator/EarningsCalculator.kt Removed legacy service in favor of MemberEarningsService.
src/main/kotlin/com/moa/service/notification/NotificationMessageBuilder.kt Switched earnings computation dependency to MemberEarningsService for clock-out notifications.
src/test/kotlin/com/moa/service/MemberEarningsServiceTest.kt Updated/renamed tests to cover MemberEarningsService behaviors (0 handling, minutes helpers).
src/test/kotlin/com/moa/service/calculator/CompensationCalculatorTest.kt Added tests for CompensationCalculator replacing the removed salary calculator tests.
src/test/kotlin/com/moa/service/calculator/SalaryCalculatorTest.kt Removed legacy tests along with legacy calculator.
Comments suppressed due to low confidence (1)

src/main/kotlin/com/moa/service/notification/NotificationMessageBuilder.kt:40

  • calculateTodayEarnings returns BigDecimal? and can return null when no policy exists, but buildClockOutBody no longer checks for null before formatting. This can lead to formatting null (and/or skipping the fallback body) when policy lookup fails. Either make calculateTodayEarnings return BigDecimal (e.g., BigDecimal.ZERO on missing policy) or restore the null guard in buildClockOutBody.
    private fun buildClockOutBody(notification: NotificationLog): String {
        val earnings = calculateTodayEarnings(notification.memberId, notification.scheduledDate)
        if (earnings == BigDecimal.ZERO) {
            return CLOCK_OUT_FALLBACK_BODY
        }
        val formatted = NumberFormat.getNumberInstance(Locale.KOREA).format(earnings)
        return notification.notificationType.getBody(formatted)
    }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

…ulatorTest for improved clarity and consistency
@jeyongsong jeyongsong merged commit 54df847 into main Mar 17, 2026
1 check passed
@jeyongsong jeyongsong deleted the refactor-workday-service branch March 17, 2026 18:49
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.

2 participants