From 3922c744a735f98f46e2d8166db4e80559cfbd82 Mon Sep 17 00:00:00 2001 From: Petri Saarinen Date: Tue, 24 Nov 2026 05:52:45 +0200 Subject: [PATCH] Add time tracking on tasks with a weekly sheet Phase 1, item 8 (last of phase 1). New TimeTracking module: - One entry per user, task and day (0.25-24 h in quarters, with a note); the job and work type are copied from the task. A user's day cannot exceed 24 h, and hours on a done, invoiced, billed or archived job cannot be added or changed. - Weekly sheet /time: tasks as rows (own open tasks, tasks with hours that week, tasks added by search), days as columns, row, day and week totals, week navigation. A cell saves on change and an empty cell removes the entry; on phones one day at a time. Saves and errors are announced, errors are tied to their cell. - Task booking page /time/tasks/{task}: date, hours and note, added to the day's entry; own entries with edit and remove. - Anyone but subcontractors may book on any unlocked task; subcontractors only on jobs they are attached to. Jobs module: - JobStatus::locksTime(), BookableTask and task queries for booking. - A task with time entries cannot be removed (TaskUsage contract, provided by TimeTracking); the job page links tasks to booking. - The "involved in a job" rule is shared in JobInvolvement. Spec and CLAUDE.md updated. Co-Authored-By: Claude Opus 5.5 --- CLAUDE.md | 6 +- .../Application/Contracts/TaskQueries.php | 28 ++ .../Jobs/Application/Contracts/TaskUsage.php | 14 + .../Jobs/Application/DTOs/BookableTask.php | 40 ++ .../Jobs/Application/UseCases/RemoveTask.php | 12 +- app/Modules/Jobs/Domain/Enums/JobStatus.php | 8 + .../Domain/Exceptions/TaskHasTimeEntries.php | 15 + .../Jobs/Infrastructure/NothingUsesTasks.php | 16 + .../Persistence/JobInvolvement.php | 37 ++ .../EloquentCustomerJobQueries.php | 11 +- .../Repositories/EloquentTaskQueries.php | 94 ++++ .../Providers/JobsServiceProvider.php | 4 + .../Presentation/Livewire/⚡show.blade.php | 16 + .../Contracts/TimeEntryQueries.php | 28 ++ .../Application/DTOs/TimeEntrySummary.php | 15 + .../TimeTracking/Application/DTOs/WeekRow.php | 22 + .../Application/DTOs/WeekSheet.php | 23 + .../Application/Services/TimeBooking.php | 63 +++ .../Application/UseCases/AddTaskHours.php | 57 +++ .../Application/UseCases/RemoveTimeEntry.php | 36 ++ .../Application/UseCases/SetDayHours.php | 63 +++ .../Application/UseCases/UpdateTimeEntry.php | 46 ++ .../Domain/Contracts/TimeEntryRepository.php | 27 ++ .../Domain/Entities/TimeEntry.php | 102 +++++ .../Domain/Exceptions/DailyHoursExceeded.php | 15 + .../Domain/Exceptions/InvalidWorkedHours.php | 15 + .../Domain/Exceptions/TaskNotBookable.php | 15 + .../Domain/Exceptions/TimeEntryNotFound.php | 18 + .../Domain/Exceptions/TimeLocked.php | 15 + .../Domain/ValueObjects/WorkedHours.php | 81 ++++ .../Persistence/Eloquent/TimeEntryModel.php | 49 ++ .../Repositories/EloquentTimeEntryQueries.php | 73 +++ .../EloquentTimeEntryRepository.php | 75 +++ .../Providers/TimeTrackingServiceProvider.php | 48 ++ .../TaskUsageFromTimeEntries.php | 19 + .../Presentation/Livewire/⚡task.blade.php | 312 +++++++++++++ .../Presentation/Livewire/⚡week.blade.php | 428 ++++++++++++++++++ .../TimeTracking/Presentation/Routes/web.php | 11 + bootstrap/providers.php | 3 + database/factories/TimeEntryFactory.php | 31 ++ ...11_23_173341_create_time_entries_table.php | 38 ++ docs/maarittely.md | 11 +- lang/fi/jobs.php | 3 + lang/fi/layout.php | 1 + lang/fi/time.php | 66 +++ resources/views/layouts/app.blade.php | 2 + .../Browser/TimeTrackingAccessibilityTest.php | 78 ++++ tests/Fakes/FakeTaskQueries.php | 53 +++ tests/Fakes/FakeTaskUsage.php | 16 + tests/Fakes/InMemoryTimeEntryRepository.php | 59 +++ .../Modules/TimeTracking/TimeEntriesTest.php | 61 +++ .../Jobs/Application/TaskUseCasesTest.php | 15 +- .../Modules/TimeTracking/TimeTrackingTest.php | 121 +++++ 53 files changed, 2496 insertions(+), 19 deletions(-) create mode 100644 app/Modules/Jobs/Application/Contracts/TaskUsage.php create mode 100644 app/Modules/Jobs/Application/DTOs/BookableTask.php create mode 100644 app/Modules/Jobs/Domain/Exceptions/TaskHasTimeEntries.php create mode 100644 app/Modules/Jobs/Infrastructure/NothingUsesTasks.php create mode 100644 app/Modules/Jobs/Infrastructure/Persistence/JobInvolvement.php create mode 100644 app/Modules/TimeTracking/Application/Contracts/TimeEntryQueries.php create mode 100644 app/Modules/TimeTracking/Application/DTOs/TimeEntrySummary.php create mode 100644 app/Modules/TimeTracking/Application/DTOs/WeekRow.php create mode 100644 app/Modules/TimeTracking/Application/DTOs/WeekSheet.php create mode 100644 app/Modules/TimeTracking/Application/Services/TimeBooking.php create mode 100644 app/Modules/TimeTracking/Application/UseCases/AddTaskHours.php create mode 100644 app/Modules/TimeTracking/Application/UseCases/RemoveTimeEntry.php create mode 100644 app/Modules/TimeTracking/Application/UseCases/SetDayHours.php create mode 100644 app/Modules/TimeTracking/Application/UseCases/UpdateTimeEntry.php create mode 100644 app/Modules/TimeTracking/Domain/Contracts/TimeEntryRepository.php create mode 100644 app/Modules/TimeTracking/Domain/Entities/TimeEntry.php create mode 100644 app/Modules/TimeTracking/Domain/Exceptions/DailyHoursExceeded.php create mode 100644 app/Modules/TimeTracking/Domain/Exceptions/InvalidWorkedHours.php create mode 100644 app/Modules/TimeTracking/Domain/Exceptions/TaskNotBookable.php create mode 100644 app/Modules/TimeTracking/Domain/Exceptions/TimeEntryNotFound.php create mode 100644 app/Modules/TimeTracking/Domain/Exceptions/TimeLocked.php create mode 100644 app/Modules/TimeTracking/Domain/ValueObjects/WorkedHours.php create mode 100644 app/Modules/TimeTracking/Infrastructure/Persistence/Eloquent/TimeEntryModel.php create mode 100644 app/Modules/TimeTracking/Infrastructure/Persistence/Repositories/EloquentTimeEntryQueries.php create mode 100644 app/Modules/TimeTracking/Infrastructure/Persistence/Repositories/EloquentTimeEntryRepository.php create mode 100644 app/Modules/TimeTracking/Infrastructure/Providers/TimeTrackingServiceProvider.php create mode 100644 app/Modules/TimeTracking/Infrastructure/TaskUsageFromTimeEntries.php create mode 100644 app/Modules/TimeTracking/Presentation/Livewire/⚡task.blade.php create mode 100644 app/Modules/TimeTracking/Presentation/Livewire/⚡week.blade.php create mode 100644 app/Modules/TimeTracking/Presentation/Routes/web.php create mode 100644 database/factories/TimeEntryFactory.php create mode 100644 database/migrations/2026_11_23_173341_create_time_entries_table.php create mode 100644 lang/fi/time.php create mode 100644 tests/Browser/TimeTrackingAccessibilityTest.php create mode 100644 tests/Fakes/FakeTaskQueries.php create mode 100644 tests/Fakes/FakeTaskUsage.php create mode 100644 tests/Fakes/InMemoryTimeEntryRepository.php create mode 100644 tests/Feature/Modules/TimeTracking/TimeEntriesTest.php create mode 100644 tests/Unit/Modules/TimeTracking/TimeTrackingTest.php diff --git a/CLAUDE.md b/CLAUDE.md index e675f47..f7d034e 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -4,7 +4,7 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co ## Project -An ERP / work-management system (*toiminnanohjausjärjestelmä*) for a small (5–10 person) Finnish media/marketing company. Stack: Laravel 13, Livewire 4 (single-file components), TallStackUI 4 (Blade components, no prefix: ``, ``), Tailwind 4, Vite 8, Pest, Larastan. Domain code lives in modules under `app/Modules` (so far `Shared`, `Users`, `Customers`, `Catalog` (service units, services and work types, managed on the Pohjatiedot page) and `Jobs` (customer jobs: numbering, members, tags, links, history)); `/` is still a temporary Livewire demo page behind login (`resources/views/pages/⚡home.blade.php`, layout `resources/views/layouts/app.blade.php`, which has the main menu and logout for signed-in users). +An ERP / work-management system (*toiminnanohjausjärjestelmä*) for a small (5–10 person) Finnish media/marketing company. Stack: Laravel 13, Livewire 4 (single-file components), TallStackUI 4 (Blade components, no prefix: ``, ``), Tailwind 4, Vite 8, Pest, Larastan. Domain code lives in modules under `app/Modules` (so far `Shared`, `Users`, `Customers`, `Catalog` (service units, services and work types, managed on the Pohjatiedot page) `Jobs` (customer jobs: numbering, members, tags, links, history, tasks) and `TimeTracking` (hours on tasks: weekly sheet and task booking page)); `/` is still a temporary Livewire demo page behind login (`resources/views/pages/⚡home.blade.php`, layout `resources/views/layouts/app.blade.php`, which has the main menu and logout for signed-in users). - **The specification is `docs/maarittely.md`** (Finnish). It defines roles and the permission table, money visibility, customers, customer jobs (*asiakastyö*) with fields and enum keys, Kanban, tasks, time entries, expenses, the service unit → service → work type hierarchy and pricing, Fennoa billing export, the data model, the phases with phase 1 in detail, and open questions. Read it before designing any domain feature. `määrittely.txt` is the original description with the customer's answers to questions 1–53, referenced as *(K12)* in the spec. - **Language rule:** code (identifiers, tables, columns, enum keys) is in English; the specification and the UI are in Finnish. Keep UI strings in translation files from the start. @@ -22,7 +22,7 @@ Read `docs/architecture.md` (Finnish) before adding or changing domain code. `ap - **Infrastructure** has Eloquent models named `…Model`, repository and query implementations, and the module's service provider (bindings, routes, `Livewire::addNamespace`), which is registered in `bootstrap/providers.php`. Migrations and factories stay in `database/`. - **Presentation** is Livewire SFC pages in `Presentation/Livewire` (`::page`), Livewire Form objects for input validation, and `Presentation/Routes/web.php`. Pages call use cases and query contracts, and turn domain exceptions into field errors with translated messages. - Modules talk only through another module's Application contracts or events, never its Infrastructure or Eloquent models. Exceptions: `App\Models\User` (Laravel's auth model, owned by `Users`) is used through `auth()`/Gate, and `Users\Domain\Enums\Role` may be used in any module's Gate rules. -- **Authorization:** define abilities with `Gate::define` in the owning module's provider (`users.manage`, `customers.use`, `catalog.manage`, `jobs.view`, `jobs.view-job`, `jobs.manage`, `jobs.archive`, `jobs.set-billing-status`, `jobs.manage-tasks`, `jobs.update-task-status`). Protect routes with `can:` and also call `$this->authorize()` in each Livewire page's `mount()` and in every action. Mark record ids on Livewire pages `#[Locked]`. +- **Authorization:** define abilities with `Gate::define` in the owning module's provider (`users.manage`, `customers.use`, `catalog.manage`, `jobs.view`, `jobs.view-job`, `jobs.manage`, `jobs.archive`, `jobs.set-billing-status`, `jobs.manage-tasks`, `jobs.update-task-status`, `time.use`, `time.book`). Protect routes with `can:` and also call `$this->authorize()` in each Livewire page's `mount()` and in every action. Mark record ids on Livewire pages `#[Locked]`. - **Login** is the `Users` module: `Auth::attemptWhen` with `CheckLoginAllowed` (active, intern's last day not passed), and the `EnsureAccountIsUsable` web middleware ends sessions of users who are no longer allowed in. Nobody handles passwords: new users and "forgot password" get the same emailed set-password link, and when an admin creates a user or asks for a new link, the link is also shown to the admin to copy. Admin links use the `admin_links` broker (own table, valid 72 h); forgot-password links use the default broker (60 min); the reset page accepts both, and using or issuing a link ends the user's earlier links. `AuthenticateSession` ends a user's other sessions when the password changes. Passwords need 12+ characters with mixed case, a number and a symbol (`Password::defaults` in `UsersServiceProvider`). - `tests/Unit/ArchitectureTest.php` enforces these rules for every module. Domain and Application files declare `strict_types=1`. Test domain rules and use cases in `tests/Unit` without Laravel (fakes in `tests/Fakes`), and repositories and pages in `tests/Feature`. - Generate module files with Artisan, then edit them: `php artisan make:class Modules////` for classes, `make:test --pest [--unit] Modules//Test` for tests, `make:migration` for migrations. Add `declare(strict_types=1);` to Domain and Application files. @@ -50,7 +50,7 @@ Accessibility is a contractual acceptance criterion. It covers the whole UI: nav - Make everything work with the keyboard alone, with a visible focus indicator and no focus traps. Use `` for dialogs (not ``, see above) and check that focus moves in and returns. Drag and drop uses Livewire's `wire:sort` (see `jobs::board`), and every drag has a keyboard alternative (e.g. a status select on each card). - The layout (`resources/views/layouts/app.blade.php`) provides a skip link and a `
` landmark. Keep them, and add `