Repository navigation
Format numbers, amounts, dates and addresses as a country writes them - #370
Closed
jakejackson1 wants to merge 1 commit into
Closed
jakejackson1 wants to merge 1 commit into
jakejackson1 wants to merge 1 commit into
Conversation
jakejackson1
force-pushed
the
einvoice/3-formatter
branch
from
September 23, 2026 02:12
d1e4615 to
f6a4d41
Compare
jakejackson1
force-pushed
the
einvoice/3-formatter
branch
from
September 23, 2026 02:23
f6a4d41 to
5327761
Compare
jakejackson1
force-pushed
the
einvoice/3-formatter
branch
2 times, most recently
from
September 23, 2026 11:59
02d1d58 to
47d19a6
Compare
jakejackson1
force-pushed
the
einvoice/3-formatter
branch
from
September 24, 2026 00:25
47d19a6 to
55d53fc
Compare
jakejackson1
force-pushed
the
einvoice/3-formatter
branch
2 times, most recently
from
September 24, 2026 01:27
c877dc1 to
f5deb6a
Compare
A Formatter writes a document's numbers, amounts, rates and dates by the convention of a country's preset, and lays out each party's address as that party's country does: - 21 presets following CLDR: the United States, English Canada and Quebec, Australia, New Zealand, the United Kingdom, China, Japan, India, and the ten most populous EU countries plus Sweden, with Dutch and French Belgium. A preset is AbstractPreset's properties, overridden where its country differs; PresetInterface is there for any other. - India's lakh grouping, the whole four-digit numbers of Spain, Poland and Portugal, currencies without a minor unit, and each language's month names for dates written out. - withDateFormat(), withLongDates(), withCurrencyFormat(), withPercentFormat() and withAddressFormat() adjust a copy. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jakejackson1
force-pushed
the
einvoice/3-formatter
branch
from
September 24, 2026 03:09
f5deb6a to
5f6fb72
Compare
This was referenced Sep 27, 2026
Member
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Third of four stacked PRs replacing #327. It's based on #369, so this diff shows only its own changes.
Summary
A printed invoice has to write its amounts, rates, dates and addresses the way its reader's country does:
1.021,11 €in Germany,$1,021.11in the US, andNew York, NY 10118but75002 Paris. This PR addsFormatter, which does that, and presets for 21 conventions. The HTML writer in #371 uses it, and it works just as well on the model's getters for a layout of your own.A
Formattermust be given a preset, because there's no default convention:Presets (
Mpdf\Invoice\Preset)UnitedStatesPreset$1,021.115.5%09/23/2026CanadaEnglishPreset$1,021.115.5%2026-09-23CanadaQuebecPreset1 021,11 $5,5 %2026-09-23AustraliaPreset$1,021.115.5%23/09/2026NewZealandPreset$1,021.115.5%23/09/2026UnitedKingdomPreset£1,021.115.5%23/09/2026ChinaPreset¥1,021.115.5%2026-09-23JapanPreset¥1,0215.5%2026/09/23IndiaPreset₹12,34,567.255.5%23/09/2026GermanyPreset1.021,11 €5,5 %23.09.2026FrancePreset1 021,11 €5,5 %23/09/2026ItalyPreset1.021,11 €5,5%23/09/2026SpainPreset1021,11 €(10.211,11 €from five digits)5,5 %23/09/2026PolandPreset1021,11 zł(10 211,11 złfrom five digits)5,5%23.09.2026RomaniaPreset1.021,11 lei5,5 %23.09.2026NetherlandsPreset€ 1.021,115,5%23-09-2026BelgiumDutchPreset€ 1.021,115,5%23/09/2026BelgiumFrenchPreset1.021,11 €5,5 %23/09/2026CzechiaPreset1 021,11 Kč5,5 %23.09.2026PortugalPreset1021,11 €(10 211,11 €from five digits)5,5%23/09/2026SwedenPreset1 021,11 kr5,5 %2026-09-23These are the ten most populous EU countries plus Sweden, the UK, the US, Canada, Australia, New Zealand, China, Japan and India. A country with two conventions has a preset for each. They follow CLDR, and their spaces are no-break spaces.
Other currencies: a preset formats its own country's currency, and writes any other with its code after the amount, e.g.
1,021.11 EURunderUnitedStatesPreset.Decimals:
£0.125, the same figure the XML carries.Sign: the minus sign goes before any symbol:
-$100.00.Dates in words:
withLongDates()switches to:23 de septiembre de 2026,September 23, 2026,2026年9月23日.{month}:withDateFormat('jS {month} Y')gives1st January 2020.Adjusting:
withDateFormat(),withLongDates(),withCurrencyFormat(),withPercentFormat()andwithAddressFormat()each return an adjusted copy:Another country: extend
AbstractPreset, whose settings are properties.5.5%.PresetInterfacefrom scratch.Addresses
Formatter::address()lays out an address the way the party's country does, whichever preset the formatter uses:New York, NY 10118Toronto ON M5V 2T6Auckland 1010London, thenSW1A 2AAon its own lineMumbai 400020, thenMaharashtraon its own lineChiyoda-ku, Tokyo 100-000175002 Paris, with any province after:00144 Roma RMwithAddressFormat('BR', ['{street}', '{additional}', '{city} - {subdivision}', '{postcode}', '{country}'])adds or replaces a country's layout.Your own printed layout
Every value on the invoice has a getter, and so do its totals. Pass them through a
Formatter:The printed totals match the embedded XML, because both come from the same calculation.
Verification
FormatterTest:with…()copies;--flavour 3b).composer csand PHPStan pass.🤖 Generated with Claude Code