From c11de9a599d7d11e2b8faaf112279c40e3846a77 Mon Sep 17 00:00:00 2001 From: johnnyq Date: Thu, 5 Nov 2026 13:24:59 -0500 Subject: [PATCH] Drop the phone formats build script from scripts/ - it is a maintainer tool, not one for installs - and say in functions/phone_formats.php where its rules came from (libphonenumber v9.0.43's PhoneNumberMetadata.xml), how they were taken and to make it again from a newer release rather than edit it by hand; changelog updated --- CHANGELOG.md | 2 +- functions/phone_formats.php | 17 ++++-- scripts/phone_formats_build.php | 98 --------------------------------- 3 files changed, 13 insertions(+), 104 deletions(-) delete mode 100644 scripts/phone_formats_build.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b716b9ef..83ff1dca6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -49,7 +49,7 @@ Update from Maintenance > Update — Queue Update hands the job to cron, which u - Booking: `billingStripeBook()` checks that `itflow_invoices` and `itflow_fees` add up to `amount_received` and refuses an `itflow_fees` that doesn't read. For each invoice it calls `billingCardFeeAdd($invoice_id, $fee, $date)` before the payment, which inserts a Card Fee line (`BILLING_CARD_FEE_NAME`, no tax, no product) and raises `invoice_amount` by the fee directly rather than through `billingRecalc()`, so the invoice's other lines aren't re-taxed and the payment pays it to the cent. The payment is what was owed plus the fee. A PaymentIntent without `itflow_fees`, from before, books as it did. The guest return, autopay and Charge Saved Card do the same, and now compare the amount received with the balance and fee in whole cents (autopay and Charge Saved Card compared whole dollars with `intval()`). - Refunding a Stripe payment (`refund_payment_stripe`) retrieves its PaymentIntent and calls `billingCardFeeRemove($invoice_id, $fee)`, which deletes the latest Card Fee line of that amount and lowers `invoice_amount` to match, before the invoice's status is worked out again. - `paymentProviderCheck()` takes `card_fee`, `card_fee_percent` (0 to 15) and `card_fee_fixed` (0 to 100), needs at least one rate above 0 when it is on, and keeps the saved rates when it is off. `paymentProviderChangeLines()` and the Create audit line include it, through the new `paymentProviderCardFeeText()`. The client's switch is `agent/modals/client/client_card_fee_field.php`, shown on the Billing tab of Add and Edit Client while Stripe is set up, and saved through `card_fee_field` and `card_fee_exempt` in `agent/post/client_model.php`. -- `formatPhoneNumber()` now formats with Google libphonenumber's rules (the data intl-tel-input's bundled utils use), from the new `functions/phone_formats.php`: for each calling code's main country, its national prefix, how that prefix is parsed off (`nationalPrefixForParsing` and its transform rule), the general number pattern and the number formats (pattern, format, last leading-digits pattern, national prefix formatting rule, international format). It's loaded the first time a number is formatted, and built by `scripts/phone_formats_build.php` from `PhoneNumberMetadata.xml` (v9.0.43 now) - run it again for a newer release. `phoneParts()` takes the national prefix off the stored digits as libphonenumber does (only when what's left still matches the general pattern, or the whole didn't), and a leading `00`+code or code typed into the number; `phoneFormatWith()` picks the first format whose leading digits and pattern fit. With the country code it writes the international format, without it the national format with the prefix rule; `+1` keeps `(412) 555-0100` after the code. A number no format fits shows its digits, without the prefix after a country code and as stored without one. Checked against intl-tel-input v29.2.3's utils on all 1,450 example numbers in the metadata, stored with and without the national prefix: the international format (`+1` apart, as above) and the dial number match for every one, and the national format for all but five that no format fits, which keep the 0 they were typed with. +- `formatPhoneNumber()` now formats with Google libphonenumber's rules (the data intl-tel-input's bundled utils use), from the new `functions/phone_formats.php`: for each calling code's main country, its national prefix, how that prefix is parsed off (`nationalPrefixForParsing` and its transform rule), the general number pattern and the number formats (pattern, format, last leading-digits pattern, national prefix formatting rule, international format). It's loaded the first time a number is formatted, and was made from libphonenumber v9.0.43's `PhoneNumberMetadata.xml` - its header says how, for a newer release. `phoneParts()` takes the national prefix off the stored digits as libphonenumber does (only when what's left still matches the general pattern, or the whole didn't), and a leading `00`+code or code typed into the number; `phoneFormatWith()` picks the first format whose leading digits and pattern fit. With the country code it writes the international format, without it the national format with the prefix rule; `+1` keeps `(412) 555-0100` after the code. A number no format fits shows its digits, without the prefix after a country code and as stored without one. Checked against intl-tel-input v29.2.3's utils on all 1,450 example numbers in the metadata, stored with and without the national prefix: the international format (`+1` apart, as above) and the dial number match for every one, and the national format for all but five that no format fits, which keep the 0 they were typed with. - New `phoneDialNumber($number, $country_code)` gives `+`, the code and the number without its national prefix for `tel:` links (just the digits without a code). `contactPhoneLink()` and `vendorDialNumber()` use it, as do the links that built `+code` and the stored digits themselves - the contact page and window, the client overview and list, the location page, the ticket and its quick look, the portal's home, contact and ticket pages, and the guest ticket page. The ticket quick look's link no longer runs the extension into the number; it dials it after a pause, as the contact page does. ## [26.11.2] diff --git a/functions/phone_formats.php b/functions/phone_formats.php index 28cd30e75..c3db21bef 100644 --- a/functions/phone_formats.php +++ b/functions/phone_formats.php @@ -2,11 +2,18 @@ /* * ITFlow - how phone numbers are written, by calling code (formatPhoneNumber() - * in functions/format.php). Built by scripts/phone_formats_build.php from - * Google's libphonenumber metadata, v9.0.43 - the same data the phone fields' - * intl-tel-input formats with, so a number reads the same on the page as in - * its field. Licensed under the Apache License 2.0, Copyright (C) 2009 The - * Libphonenumber Authors. Don't edit it by hand - build it again. + * in functions/format.php). Taken from Google's libphonenumber metadata, + * resources/PhoneNumberMetadata.xml at v9.0.43 - the same data the phone + * fields' intl-tel-input formats with, so a number reads the same on the page + * as in its field. Licensed under the Apache License 2.0, Copyright (C) 2009 + * The Libphonenumber Authors. When a country changes how its numbers are + * written, make it again from a newer release rather than editing it by hand. + * + * Each calling code takes its main country's rules (mainCountryForCode) - + * ITFlow keeps the calling code, not the country, and +1 is the US, Canada + * and more, written the same way. The leading digits are the last, most + * precise, pattern of each format, and the national prefix rule has $NP and + * $FG filled in. * * Each calling code, for its main country: np, the prefix dialled before a * number at home (0 in most countries, 1 in North America, none in Italy); diff --git a/scripts/phone_formats_build.php b/scripts/phone_formats_build.php deleted file mode 100644 index f0193b21b..000000000 --- a/scripts/phone_formats_build.php +++ /dev/null @@ -1,98 +0,0 @@ -\n"); - exit(1); -} - -$xml = simplexml_load_file($source); -if (!$xml) { - fwrite(STDERR, "That isn't libphonenumber's PhoneNumberMetadata.xml\n"); - exit(1); -} - -$clean = function ($text) { - return preg_replace('/\s+/', '', (string) $text); -}; -$quote = function ($text) { - return "'" . str_replace(['\\', "'"], ['\\\\', "\\'"], (string) $text) . "'"; -}; - -// The main country for each calling code -$by_code = []; -foreach ($xml->territories->territory as $territory) { - $code = (string) $territory['countryCode']; - if (!isset($by_code[$code]) || (string) $territory['mainCountryForCode'] === 'true') { - $by_code[$code] = $territory; - } -} -uksort($by_code, function ($a, $b) { - return [strlen($a), $a] <=> [strlen($b), $b]; -}); - -$lines = []; -foreach ($by_code as $code => $territory) { - $prefix = (string) $territory['nationalPrefix']; - $default_rule = (string) $territory['nationalPrefixFormattingRule']; - $formats = []; - foreach ($territory->availableFormats->numberFormat ?? [] as $format) { - $leading = ''; - foreach ($format->leadingDigits as $digits) { - $leading = $clean($digits); // the last is the most precise - } - $rule = isset($format['nationalPrefixFormattingRule']) ? (string) $format['nationalPrefixFormattingRule'] : $default_rule; - $rule = str_replace(['$NP', '$FG'], [$prefix, '$1'], $rule); - $parts = [(string) $format['pattern'], (string) $format->format, $leading, $rule, isset($format->intlFormat) ? (string) $format->intlFormat : '']; - $formats[] = '[' . implode(', ', array_map($quote, $parts)) . ']'; - } - $lines[] = ' ' . $quote($code) . " => ['np' => " . $quote($prefix) - . ", 'npfp' => " . $quote($clean($territory->nationalPrefixForParsing)) - . ", 'nptr' => " . $quote($clean($territory->nationalPrefixTransformRule)) - . ", 'valid' => " . $quote($clean($territory->generalDesc->nationalNumberPattern)) - . ", 'formats' => [" . implode(', ', $formats) . ']],'; -} - -$out = <<