Database updates: keep junk values from stopping the 26.11 update - 3.0.3 sets trip miles of a billion or more to 0 before trip_miles becomes decimal(10,1), 3.1.1 sets tax rates of 100,000% or more to 0 before tax_percent becomes decimal(9,4), and 3.5.0 leaves out a client rate of 100,000,000 or more when making Standard terms and skips clients already given them by a run that stopped part way, so an update that failed at any of these resumes cleanly when run again

This commit is contained in:
johnnyq
2026-10-29 13:45:59 -04:00
parent e6382145ef
commit 3ff116f0d3
3 changed files with 17 additions and 3 deletions

View File

@@ -7,6 +7,11 @@
defined('FROM_DB_UPDATER') || die("Direct file access is not allowed");
// Miles become decimal(10,1), which holds under a billion. A figure past
// that was typed in by mistake (New Trip takes under 100,000 now) - it
// goes to 0, or the change below is refused and the update stops here
mysqli_query($mysqli, "UPDATE `trips` SET `trip_miles` = 0 WHERE ABS(`trip_miles`) >= 1000000000");
// Trips (functions/trips.php): the client's site it went to, the ticket it
// was for, who logged it, miles as an exact number, and the end odometer
// reading's misspelt column put right

View File

@@ -7,6 +7,10 @@
defined('FROM_DB_UPDATER') || die("Direct file access is not allowed");
// A rate past what decimal(9,4) holds - 100,000% or more - was typed in by
// mistake: it goes to 0, or the change below is refused and the update stops here
mysqli_query($mysqli, "UPDATE `taxes` SET `tax_percent` = 0 WHERE ABS(`tax_percent`) >= 100000");
// A rate to the ten-thousandth of a percent (Quebec's 9.975%) rather than
// a float, a description and the registration number the rate is charged
// under, and - when a rate in use was changed - the rate that took its place

View File

@@ -68,16 +68,21 @@ defined('FROM_DB_UPDATER') || die("Direct file access is not allowed");
}
$itflow_today = date('Y-m-d');
// A client given its Standard terms by an earlier run that stopped part way is left as it is
$itflow_sql = mysqli_query($mysqli, "SELECT client_id, client_rate, client_net_terms, client_created_at, client_archived_at,
(SELECT MIN(contract_start_date) FROM contracts WHERE contract_client_id = client_id AND contract_start_date IS NOT NULL) AS first_contract_start
FROM clients ORDER BY client_id");
FROM clients
WHERE NOT EXISTS (SELECT 1 FROM contracts WHERE contract_client_id = client_id AND contract_name = 'Standard terms' AND contract_notes LIKE 'Made by the 26.11 update%')
ORDER BY client_id");
while ($itflow_sql && ($itflow_client = mysqli_fetch_assoc($itflow_sql))) {
$itflow_client_id = intval($itflow_client['client_id']);
$itflow_set = [];
// Only what differs from the defaults - a rate of nothing was no rate, the default applied
// Only what differs from the defaults - a rate of nothing was no rate, the default applied. A
// contract's rate holds under 100,000,000.00 - a rate past that was typed in by mistake, and
// is left out (the default applies), or the contract couldn't be made and the update would stop
$itflow_rate = round(floatval($itflow_client['client_rate']), 2);
if ($itflow_rate > 0 && $itflow_rate != $itflow_default_rate) {
if ($itflow_rate > 0 && $itflow_rate < 100000000 && $itflow_rate != $itflow_default_rate) {
$itflow_set[] = "contract_rate_standard = " . sprintf('%.2f', $itflow_rate);
}
if ($itflow_client['client_net_terms'] !== null && intval($itflow_client['client_net_terms']) !== $itflow_default_net) {