Write billing CSV amounts in cents and VAT rates in per mille

The invoicing import reads whole numbers: amounts are now whole cents
(400,00 € is 40000) and the VAT rate is in tenths of a percent (10 % is
100, 25,5 % is 255). The column headings say so.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-11-24 13:37:18 +02:00
co-authored by Claude Opus 5.5
parent ae7b611126
commit e521df647c
5 changed files with 15 additions and 19 deletions
+1 -1
View File
@@ -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: `<x-input>`, `<x-button>`), 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; 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) `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: 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 (`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: `<x-input>`, `<x-button>`), 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; 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) `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: 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).
- **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.
@@ -12,8 +12,9 @@ use Symfony\Component\HttpFoundation\StreamedResponse;
/**
* Downloads a created billing material as a CSV file for Excel and the
* invoicing program: one row per invoice line, semicolons, decimal
* commas and a UTF-8 BOM. Consumers' personal identity codes are included
* invoicing program: one row per invoice line, semicolons, amounts in
* whole cents (400,00 € is 40000), the VAT rate in tenths of a percent
* (10 % is 100), hours with a decimal comma, and a UTF-8 BOM. Consumers' personal identity codes are included
* for those who may see them, so the response is never cached.
*/
class DownloadBillingCsv
@@ -78,11 +79,11 @@ class DownloadBillingCsv
LineKind::MonthlyFee => 'month',
default => 'piece',
}),
self::money($row->unitPriceCents),
self::decimal($row->vatBasisPoints, 100),
self::money($row->netCents),
self::money($row->vatCents),
self::money($row->grossCents()),
(string) $row->unitPriceCents,
self::decimal($row->vatBasisPoints, 10),
(string) $row->netCents,
(string) $row->vatCents,
(string) $row->grossCents(),
];
}
@@ -95,18 +96,13 @@ class DownloadBillingCsv
return preg_match('/^[=+\-@\t\r\n]/', $value) === 1 ? "'".$value : $value;
}
private static function money(int $cents): string
{
return ($cents < 0 ? '-' : '').intdiv(abs($cents), 100).','.str_pad((string) (abs($cents) % 100), 2, '0', STR_PAD_LEFT);
}
private static function hours(int $quarters): string
{
return self::decimal($quarters * 25, 100);
}
/**
* E.g. 2550 / 100 → "25,5", 1000 / 100 → "10".
* E.g. 2550 / 10 → "255", 1000 / 100 → "10", 250 / 100 → "2,5".
*/
private static function decimal(int $value, int $divisor): string
{
+1 -1
View File
@@ -323,7 +323,7 @@ Hierarkiaa muokataan pohjatietojen hallinnasta.
- Aineistoon tulevat vain **hyväksytyt** tunnit. Hyväksymättömät tunnit näytetään luonnoksessa varoituksena linkillä hyväksyntään; ne jäävät laskuttamatta, kun työ siirtyy tilaan Lasku luotu *(valmis)*.
- **Kiinteä tarjous**: laskulle tulee yksi rivi, jonka summa on työn tarjoussumma (veroton), vain kerran. Hyväksytyt tunnit näytetään tietona ja merkitään laskutetuiksi. Kulut tulevat eriteltyinä *(valmis)*.
- Laskuttamatta jätetään työt, joiden maksuperuste on "ei laskuteta", sisäisen asiakkaan työt, kuluttajat ilman henkilötunnusta ja työt, joiden työtehtävältä puuttuu tuntihinta; syy näytetään johdolle *(valmis)*.
- **CSV-lataus** *(valmis)*: muodostetun aineiston saa ladattua CSV-tiedostona (Excel-yhteensopiva: puolipiste, desimaalipilkku, UTF-8 BOM). Jokainen laskurivi on oma rivinsä, ja siinä on laskun numero aineistossa, asiakas, asiakastyyppi, Y-tunnus, kuluttajan henkilötunnus, laskutusyksikkö, laskutusosoite, verkkolaskuosoite ja välittäjä, viite (laskun tai laskutusyksikön), työ, rivin laji, kuvaus, kirjatut tunnit, määrä ja yksikkö (h, kk, kpl), à-hinta, ALV %, veroton, ALV ja verollinen. Rivin ALV lasketaan riviltä, joten laskun ALV-summa voi erota sivun kannoittaisesta summasta sentillä. Henkilötunnus kirjoitetaan vain, jos lataajalla on oikeus nähdä se; tiedostoa ei välimuisteta, ja kaavaksi tulkittavat solut saavat eteensä heittomerkin. Sarakkeet sovitetaan Fennoan tuontimuotoon, kun esimerkki saadaan (avoin kysymys 4).
- **CSV-lataus** *(valmis)*: muodostetun aineiston saa ladattua CSV-tiedostona (Excel-yhteensopiva: puolipiste, UTF-8 BOM; rahasummat kokonaisina sentteinä, esim. 400,00 € = 40000, ALV-kanta promilleina, esim. 10 % = 100 ja 25,5 % = 255, tunnit desimaalipilkulla). Jokainen laskurivi on oma rivinsä, ja siinä on laskun numero aineistossa, asiakas, asiakastyyppi, Y-tunnus, kuluttajan henkilötunnus, laskutusyksikkö, laskutusosoite, verkkolaskuosoite ja välittäjä, viite (laskun tai laskutusyksikön), työ, rivin laji, kuvaus, kirjatut tunnit, määrä ja yksikkö (h, kk, kpl), à-hinta, ALV-kanta, veroton, ALV ja verollinen (summat sentteinä, kanta promilleina). Rivin ALV lasketaan riviltä, joten laskun ALV-summa voi erota sivun kannoittaisesta summasta sentillä. Henkilötunnus kirjoitetaan vain, jos lataajalla on oikeus nähdä se; tiedostoa ei välimuisteta, ja kaavaksi tulkittavat solut saavat eteensä heittomerkin. Sarakkeet sovitetaan Fennoan tuontimuotoon, kun esimerkki saadaan (avoin kysymys 4).
- Laskutetut tunnit pysyvät hyväksyttyinä (hyväksynnän peruminen ohittaa ne), eikä laskutettua kulua voi muuttaa tai poistaa *(valmis)*.
## 13. Ilmoitukset ja raportit *(K52, K53)*
+1 -1
View File
@@ -19,7 +19,7 @@ return [
'columns' => [
'Lasku', 'Asiakas', 'Asiakastyyppi', 'Y-tunnus', 'Henkilötunnus', 'Laskutusyksikkö', 'Laskutusosoite',
'Verkkolaskuosoite', 'Välittäjä', 'Viite', 'Työ', 'Työn nimi', 'Rivin laji', 'Kuvaus', 'Kirjatut h',
'Määrä', 'Yksikkö', 'À-hinta', 'ALV %', 'Veroton', 'ALV', 'Verollinen',
'Määrä', 'Yksikkö', 'À-hinta (snt)', 'ALV (‰)', 'Veroton (snt)', 'ALV (snt)', 'Verollinen (snt)',
],
],
@@ -105,14 +105,14 @@ it('downloads a created billing material as a CSV file for Excel', function () {
->and($rows)->toHaveCount(4)
->and($rows[1])->toBe([
'1', 'Asiakas Oy', 'Yritys', '0737546-2', '', 'Talous', "PL 10\n40100 Jyväskylä", '003707375462', 'E204503', 'PO-1',
$first->number, 'Esite', 'Tunnit', 'Taitto', '2,5', '2,5', 'h', '80,50', '25,5', '201,25', '51,32', '252,57',
$first->number, 'Esite', 'Tunnit', 'Taitto', '2,5', '2,5', 'h', '8050', '255', '20125', '5132', '25257',
])
->and($rows[2][12])->toBe('Kulu')
->and($rows[2][13])->toEndWith(': Paperi')
->and(array_slice($rows[2], 15))->toBe(['1', 'kpl', '10,00', '25,5', '10,00', '2,55', '12,55'])
->and(array_slice($rows[2], 15))->toBe(['1', 'kpl', '1000', '255', '1000', '255', '1255'])
->and(array_slice($rows[3], 0, 6))->toBe(['2', 'Kalle Kuluttaja', 'Kuluttaja', '', '131052-308T', ''])
->and($rows[3][11])->toBe("'=HYPERLINK(\"x\")")
->and($rows[3][19])->toBe('80,50');
->and($rows[3][19])->toBe('8050');
});
it('uses the billing unit reference when the jobs have none and offers the file on the pages', function () {