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
@@ -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
{