From 52b6a1f0a62c5ad9ce2669dd5f7d5da1260ade4b Mon Sep 17 00:00:00 2001 From: Petri Saarinen Date: Wed, 25 Nov 2026 08:51:02 +0200 Subject: [PATCH] Document the reports in the specification and CLAUDE.md Co-Authored-By: Claude Sonnet 5.5 --- CLAUDE.md | 6 +++--- docs/maarittely.md | 12 +++++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index e6d6e0f..1369cc1 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; workflow templates of work types with ordered steps, read through `WorkflowTemplateQueries`, from which Jobs' `AddTasksFromWorkflowTemplate` makes a job's tasks, each with its own assignee and, by default, scheduled to end on its due date with the estimate booked backwards from it (`TaskPlanner::planBackwards`, not before today); hourly rates, products and the mileage rate on the Hinnasto page, read through `PriceListQueries`, never `CatalogQueries`) `Jobs` (customer jobs: numbering, members, tags, links, history, tasks with one assignee (`tasks.assignee_user_id`) and members (`task_members`, who see the task among their own but get no bookings), task checklists, task comments (`jobs::task-comments`: anyone with `jobs.update-task-status` comments, authors edit and remove their own, `jobs.remove-any-task-comment` removes anyone's), task images (`jobs::task-images`, same rules with `jobs.remove-any-task-image`; `GdTaskImageFiles` stores an upright, at most 2560 px JPEG without EXIF and a 400 px thumbnail under `task-images/` on the private `local` disk, served only through `ShowTaskImage` after `jobs.view-job`; `RemoveTask` also deletes the files), and the task calendar `jobs::calendar`: a Gantt of tasks on their assignee's row where `ScheduleTask` moves a task's planned period and assignee and `TaskPlanner`/`TaskScheduler` book its estimate into `task_bookings` for the assignee only, split over working days with the rest moved to the next working day past the daily maximum `jobs.daily_capacity_hours`) `TimeTracking` (hours on tasks: weekly sheet and task booking page) `Expenses` (expenses on jobs with cost, markup and billed amount; reads jobs and prices through its own `ExpenseJobs`/`ExpensePricing` ports) `Billing` (the monthly billing material (its running number `billing_exports.number` is reserved only when it is created, so discarded drafts leave no gaps, and a draft has none): a draft of invoices made of done jobs and monthly fee jobs (one line per unbilled month up to the draft's month, each such job an invoice of its own), management's billable hours, and on creation invoice lines with price snapshots, downloadable as a semicolon CSV with amounts in whole cents and the VAT rate in tenths of a percent (`billing.csv`, with consumers' identity codes for those who may see them); reads and marks hours, expenses and jobs through its `BillingJobs`/`BillingHours`/`BillingExpenses`/`BillingPrices` ports, which call those modules' queries and the use cases `MarkJobHoursBilled`, `MarkJobExpensesBilled` and `ChangeJobStatus`) and `Sales` (quick sales of consumer products at the counter, credits and cash days; its `QuickSaleHours` port books product durations through Jobs' `ProvideQuickSaleTask` (the yearly "Pikamyynnit" job) and TimeTracking's `AddTaskHours`)); `/` 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; workflow templates of work types with ordered steps, read through `WorkflowTemplateQueries`, from which Jobs' `AddTasksFromWorkflowTemplate` makes a job's tasks, each with its own assignee and, by default, scheduled to end on its due date with the estimate booked backwards from it (`TaskPlanner::planBackwards`, not before today); hourly rates, products and the mileage rate on the Hinnasto page, read through `PriceListQueries`, never `CatalogQueries`) `Jobs` (customer jobs: numbering, members, tags, links, history, tasks with one assignee (`tasks.assignee_user_id`) and members (`task_members`, who see the task among their own but get no bookings), task checklists, task comments (`jobs::task-comments`: anyone with `jobs.update-task-status` comments, authors edit and remove their own, `jobs.remove-any-task-comment` removes anyone's), task images (`jobs::task-images`, same rules with `jobs.remove-any-task-image`; `GdTaskImageFiles` stores an upright, at most 2560 px JPEG without EXIF and a 400 px thumbnail under `task-images/` on the private `local` disk, served only through `ShowTaskImage` after `jobs.view-job`; `RemoveTask` also deletes the files), and the task calendar `jobs::calendar`: a Gantt of tasks on their assignee's row where `ScheduleTask` moves a task's planned period and assignee and `TaskPlanner`/`TaskScheduler` book its estimate into `task_bookings` for the assignee only, split over working days with the rest moved to the next working day past the daily maximum `jobs.daily_capacity_hours`) `TimeTracking` (hours on tasks: weekly sheet and task booking page) `Expenses` (expenses on jobs with cost, markup and billed amount; reads jobs and prices through its own `ExpenseJobs`/`ExpensePricing` ports) `Billing` (the monthly billing material (its running number `billing_exports.number` is reserved only when it is created, so discarded drafts leave no gaps, and a draft has none): a draft of invoices made of done jobs and monthly fee jobs (one line per unbilled month up to the draft's month, each such job an invoice of its own), management's billable hours, and on creation invoice lines with price snapshots, downloadable as a semicolon CSV with amounts in whole cents and the VAT rate in tenths of a percent (`billing.csv`, with consumers' identity codes for those who may see them); reads and marks hours, expenses and jobs through its `BillingJobs`/`BillingHours`/`BillingExpenses`/`BillingPrices` ports, which call those modules' queries and the use cases `MarkJobHoursBilled`, `MarkJobExpensesBilled` and `ChangeJobStatus`) and `Sales` (quick sales of consumer products at the counter, credits and cash days; its `QuickSaleHours` port books product durations through Jobs' `ProvideQuickSaleTask` (the yearly "Pikamyynnit" job) and TimeTracking's `AddTaskHours`) and `Reports` (management's reports behind `reports.view`: hours by person, unbilled hours, profitability by job and service unit, quick sales and expense reimbursements, each a `reports::` page with a period in the URL (`ReportPage` trait, `alku`/`loppu`), tables, a `` (TallStackUI's server-side `` as one image) and a CSV from `DownloadReport`; it reads the other modules only through its ports `ReportHours`, `ReportJobs`, `ReportCatalog`, `ReportPeople`, `ReportSales`, `ReportExpenses` and `ReportRevenue`, whose adapters call those modules' report queries (`TimeReportQueries`, `CustomerJobQueries::reportInfoOf`, `QuickSaleReportQueries`, `ExpenseReportQueries`, `BilledRevenueQueries`); hours are costed at the one internal hourly cost `catalog.internal_hourly_cost_cents`, set on the Hinnasto maintenance 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 is in Finnish. The UI is in Finnish (default) and English: every UI string lives in `lang/fi/*.php` **and** `lang/en/*.php` with the same keys and placeholders (`tests/Unit/TranslationFilesTest.php` fails otherwise). Number, money and date formats stay Finnish in both languages; the quick sale receipt is always Finnish. @@ -23,9 +23,9 @@ 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`, `jobs.remove-any-task-comment`, `jobs.remove-any-task-image`, `time.use`, `time.book`, `time.approve`, `time.approve-others`, `time.cancel-approval`, `jobs.unlock`, `catalog.view-prices`, `expenses.use`, `expenses.record`, `expenses.record-for-others`, `expenses.change`, `expenses.see-amount`, `sales.use`, `sales.view-all`, `sales.view-sale`, `sales.credit`, `sales.close-day`, `sales.reopen-day`, `billing.manage`, and in `Users` `money.prices`, `money.expenses`, `money.quotes`, `money.billing` for the personal money permissions of specification 2.3). 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`, `jobs.remove-any-task-comment`, `jobs.remove-any-task-image`, `time.use`, `time.book`, `time.approve`, `time.approve-others`, `time.cancel-approval`, `jobs.unlock`, `catalog.view-prices`, `expenses.use`, `expenses.record`, `expenses.record-for-others`, `expenses.change`, `expenses.see-amount`, `sales.use`, `sales.view-all`, `sales.view-sale`, `sales.credit`, `sales.close-day`, `sales.reopen-day`, `billing.manage`, `reports.view`, and in `Users` `money.prices`, `money.expenses`, `money.quotes`, `money.billing` for the personal money permissions of specification 2.3). 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`). Login allows 5 failed attempts a minute per email + IP and 20 per IP; the forgot-password page 5 requests a minute per IP. -- **Main menu**: the layout renders the groups of `App\View\MainMenu` (Työt, Oma kirjaus, Asiakkaat ja myynti, Hallinto, Ylläpito) as disclosure popovers (`resources/views/components/nav-group.blade.php`). A new page is added to `MainMenu::definition()` with the Gate ability of its route; groups with no allowed links disappear. +- **Main menu**: the layout renders the groups of `App\View\MainMenu` (Työt, Oma kirjaus, Asiakkaat ja myynti, Hallinto, Raportit, Ylläpito) as disclosure popovers (`resources/views/components/nav-group.blade.php`). A new page is added to `MainMenu::definition()` with the Gate ability of its route; groups with no allowed links disappear. - **Notifications** are their own module (`Notifications`): the header's bell `notifications::bell` (beside the profile menu) shows the unseen count and the last 7 days of `user_notifications`, and opening it marks them seen. Texts are made at display time from `NotificationType` and its `params` (`lang/*/notifications.php`). `NotifyTasksStartingSoon` (`notifications:task-starts`, scheduled daily at 14.00 business time in `routes/console.php`) notifies the assignee and members of tasks starting by the next working day through Jobs' `UpcomingTasks` port; `dedupe_key` keeps reruns from notifying twice. Jobs' use cases publish `PeopleAddedToTask` and `PeopleAddedToJob` (Domain events, after commit) when someone else is made a task's assignee or member or gets a role on a job; `NotifyAddedPeople` turns them into notifications at once, never for the actor's own changes. The scheduler needs `php artisan schedule:run` every minute (cron / Windows Task Scheduler; locally `php artisan schedule:work`). - **Holidays** are Shared: `Shared\Application\UseCases\HolidayCalendar` gives the Finnish public holidays (`FinnishHolidays`, calculated) minus those the admin took out of use plus company days off (`holiday_overrides`), edited on `shared::holidays` (`/settings/holidays`, gate `settings.manage`). - **Company details** (name, business ID, address, phone, email) are kept by `Shared\Application\UseCases\CompanyDetailsStore` in the settings (`shared.company_*`) and edited by the admin on `shared::company` (`/settings/company`, gate `settings.manage`). `BusinessId` (Y-tunnus with check digit) is a Shared value object. The name at the left of the main menu is the optional "Valikon nimi" (`shared.company_menu_name`), read with `CompanyDetailsStore::menuName()` (falls back to `config('app.name')`). diff --git a/docs/maarittely.md b/docs/maarittely.md index 3c8224c..194279a 100644 --- a/docs/maarittely.md +++ b/docs/maarittely.md @@ -306,6 +306,7 @@ Hierarkiaa muokataan pohjatietojen hallinnasta. - **Tuntihinnasto**: tuntihinta on työtehtäväkohtainen (esim. ohjelmointityö 85 €/h, vaativa 110 €/h). Ei asiakas- eikä tekijäkohtaisia hintoja. - **Tuotteet**: kiinteähintaiset kappaletuotteet (passikuvat, tulosteet); hinta, yksikkö, kuluttajatuote-merkintä (näkyy kaikille) ja automaattisen tuntikirjauksen kesto. Yksikkö valitaan listasta: kpl, sivu, m², m, h, paketti. Jos kesto on annettu (0,25 h tarkkuudella, enintään 24 h), tuotteelle valitaan työtehtävä, jolle tunnit kirjataan. Tuotteita ei poisteta, vaan ne poistetaan käytöstä. - **Km-hinta** (asetus). +- **Sisäinen tuntikustannus** (asetus, €/h ALV 0): yksi yhteinen työtunnin kustannus (palkka ja sivukulut), jolla kannattavuusraportti hinnoittelee tehdyt tunnit (luku 13) *(valmis)*. - **ALV-kannat**: nimi ja prosentti (esim. Yleinen 25,5 %, Alennettu 13,5 %, Alennettu 10 %, Veroton 0 %); ylläpidetään hinnastossa. Tuotteelle valitaan kanta. Yksi kanta on oletus, jota käytetään tunneille, kuluille ja km-kuluille laskuaineistossa; oletus on aina käytössä. Kun lain mukainen kanta muuttuu, kannan prosentti muutetaan, ja muutos koskee kaikkia kantaa käyttäviä tuotteita. - Hinnat verottomina, enintään kaksi desimaalia. Poikkeus: kuluttajatuotteen hinta syötetään ja tallennetaan verollisena (pyöreät kassahinnat), ja veroton hinta lasketaan kannasta. - Hinnoilla ei ole historiaa: laskuaineiston rivi tallentaa yksikköhinnan muodostushetkellä, joten hinnan muutos koskee vain myöhempiä aineistoja ja myyntejä. @@ -333,7 +334,12 @@ Hierarkiaa muokataan pohjatietojen hallinnasta. - Tehtävä alkaa *(valmis)*: ajo joka päivä klo 14.00 (`notifications:task-starts`) ilmoittaa arkipäivänä tehtävän tekijälle ja jäsenille tehtävistä, joiden suunniteltu alku (tehtäväkalenteri) on seuraavana arkipäivänä tai sitä ennen (perjantaina myös la–ma alkavista). Arkipyhät ja yrityksen vapaapäivät eivät ole arkipäiviä. Valmiista tehtävistä ja arkistoiduista töistä ei ilmoiteta, eikä samasta alusta ilmoiteta kahdesti. - Lisätty tehtävään tai työhön *(valmis)*: kun joku toinen tekee käyttäjästä tehtävän tekijän tai jäsenen (myös tehtävän siirto kalenterissa hänen rivilleen ja tehtävät työnkulkupohjasta) tai antaa hänelle roolin asiakastyössä (vastuuhenkilö, yhteyshenkilö, laskuttaja tai jäsen), käyttäjä saa ilmoituksen heti. Omista muutoksista ei ilmoiteta. - Myöhemmin muita ilmoituksia (esim. määräpäivä lähestyy). -- Johdon raportit (myöhemmin): tunnit henkilöittäin, laskuttamattomat tunnit, kannattavuus asiakastöittäin ja palveluyksiköittäin, pikamyynnit, kulukorvaukset. +- **Johdon raportit** *(valmis)*: valikon Raportit-ryhmä, vain pääkäyttäjälle ja johdolle (`reports.view`). Raportit valitaan aikavälillä (alku- ja loppupäivä, pikavalinnat tämä/edellinen kuukausi ja vuosi), joka säilyy osoitteessa. Jokaisessa raportissa on taulukko summariveineen, pylväskaavio samoista luvuista (kuvana, jonka luvut ovat taulukossa) ja CSV-lataus samoilla suodattimilla (puolipiste, UTF-8 BOM, rahasummat sentteinä, tunnit desimaalipilkulla). + - **Tunnit henkilöittäin**: aikavälin tunnit henkilöittäin: yhteensä, asiakastyö, sisäinen työ (sisäisen asiakkaan työt), hyväksymättä ja laskutettu; henkilön erittely työtehtävittäin ja asiakastöittäin. Rajaus työn palveluyksiköllä tai asiakkaalla. + - **Laskuttamattomat tunnit**: tunnit, joita mikään laskuaineisto ei ole laskuttanut, valittuun päivään asti, asiakastöittäin ja työtehtävittäin (hyväksytyt ja hyväksymättömät, vanhin kirjaus). Arvo on tunnit × työtehtävän tuntihinta töillä, jotka laskutetaan tunneittain (tuntityö, hinnasto); kiinteän tarjouksen ja kk-laskutuksen tunnit sisältyvät hintaan. Sisäiset ja ei laskutettavat työt eivät ole mukana. Kaavio: arvo työtehtävien palveluyksiköittäin. + - **Kannattavuus** asiakastöittäin ja palveluyksiköittäin aikavälin tapahtumista: aikavälillä tehdyt tunnit ja kirjatut kulut sekä aikavälin laskutuskuukausien luotujen laskuaineistojen laskutus (työ: tunnit, kiinteä hinta, kuukausihinnat; kulut erikseen). Kustannukset ovat kulujen hankintahinta ja tunnit × **sisäinen tuntikustannus**, joka on yksi yhteinen €/h-hinta (asetus `catalog.internal_hourly_cost_cents`, hinnaston ylläpidossa). Kate = laskutus − kustannukset, kate-% laskutuksesta ja toteutunut €/h = laskutettu työ / tehdyt tunnit. Ilman tuntikustannusta katetta ei lasketa, ja sivu neuvoo asettamaan sen. Usean palveluyksikön työn luvut jaetaan tasan sen palveluyksiköille. Sisäiset työt näytetään valinnalla. + - **Pikamyynnit**: aikavälin myynnit ja hyvitykset kassapäivittäin (määrä, käteinen, kortti, päätetty), tuotteittain, myyjittäin ja ALV-kannoittain; vero lasketaan kunkin päivän kannan summasta kuten kassapäivän saldossa. Päättämättömistä päivistä kerrotaan. Kaavio päivittäin, yli 62 päivän aikavälillä kuukausittain. + - **Kulukorvaukset**: työntekijöiden itse maksamat kulut aikavälillä henkilöittäin (päivä, laji, kuvaus tai km-kulun kohde ja tarkoitus, työ, km, summa ALV 0) välisummineen; tulostettava palkanlaskentaa varten. Korvausten maksua ei seurata (luku 10). Oletuksena edellinen kuukausi. ## 14. Tietomalli @@ -356,7 +362,7 @@ Taulut ja tärkeimmät sarakkeet. Kaikissa tauluissa on `id` ja `created_at`/`up - `vat_rates` *(V2, olemassa)*: `name`, `basis_points` (sadasosaprosentteina, 2550 = 25,5 %), `is_default`, `is_active`, `sort_order` - `products` *(V2, olemassa)*: `name`, `unit` (`piece`/`page`/`square_metre`/`metre`/`hour`/`package`), `price_cents` (kuluttajatuotteella verollinen, muuten veroton), `vat_rate_id`, `is_consumer_product`, `auto_hours`, `work_type_id` (nullable, pakollinen jos `auto_hours` > 0), `is_active`, `sort_order` - `workflow_templates` *(V3, olemassa)*: `work_type_id`, `name` (yksilöllinen työtehtävän sisällä), `is_active`; `workflow_template_steps`: `workflow_template_id`, `work_type_id` (nullable = pohjan työtehtävä), `title`, `description`, `sort_order` -- `settings` *(V2, olemassa)*: `key` (uniikki, omistajamoduulin etuliite, esim. `catalog.mileage_rate_cents`), `value` (esim. km-hinta, työajanseuranta päällä, `jobs.daily_capacity_hours` = päiväkatto tunteina, oletus 8) +- `settings` *(V2, olemassa)*: `key` (uniikki, omistajamoduulin etuliite, esim. `catalog.mileage_rate_cents`), `value` (esim. km-hinta, `catalog.internal_hourly_cost_cents` = sisäinen tuntikustannus kannattavuusraporttiin *(V4)*, työajanseuranta päällä, `jobs.daily_capacity_hours` = päiväkatto tunteina, oletus 8) - `holiday_overrides` *(V3, olemassa)*: `date` (uniikki), `is_holiday` (false = laskettu arkipyhä poistettu käytöstä, true = yrityksen oma vapaapäivä), `name` (oman päivän nimi) **Jobs** (asiakastyöt) @@ -416,7 +422,7 @@ Hinnasto ja tuotteet, rahakentät ja henkilökohtaiset näkyvyysoikeudet, kulut, Tarkistuslistat *(valmis)*, kommentit *(valmis)*, kuvat *(valmis)*, työnkulkupohjat *(valmis)*, tehtäväkalenteri henkilöittäin ja arkipyhät *(valmis; korvaa tehtävien Kanban-sarakkeet, K34)*. **Vaihe 4 – laajennukset** -Alihankkijoiden näkymät ja rajaukset, raportit, ilmoitukset *(osittain: kello ja tehtävän alku)*, Fennoa-rajapinta, PWA, kenttien yksinkertaistus palveluyksiköittäin *(K31; siirretty vaiheesta 3)*. +Alihankkijoiden näkymät ja rajaukset, raportit *(valmis)*, ilmoitukset *(osittain: kello ja tehtävän alku)*, Fennoa-rajapinta, PWA, kenttien yksinkertaistus palveluyksiköittäin *(K31; siirretty vaiheesta 3)*. ## 16. Vaiheen 1 tarkka sisältö